Last Updated: February 25, 2016
·
1.117K
· pentago

Automated Timestamped Nightly TAR Backups

Create a new file (backup.sh) with your text editor and make it executable (chmod +x backup.sh)

Script contents:

#!/bin/zsh

location=/mnt/D/Dropbox/Linux/backups
includes=/mnt/D/Dropbox/Linux/backups/includes
excludes=/mnt/D/Dropbox/Linux/backups/excludes
date=$(date +%d.%m.%y--%I.%M%p)
file="$location/backup-$date.tar"

tar -cvpf $file --files-from=$includes --exclude-from=$excludes

Include file should contain paths of stuff you want backed up:

Example:

/home/pentago/.config/sublime-text-3/
/etc/pacman.conf
/etc/makepkg.conf

Exclude file should contain paths to junk you don't want in your tarball and whose parent is already included in includes file:

Example:

/home/pentago/.config/sublime-text-3/Cache
/home/pentago/.config/sublime-text-3/Backup
/home/pentago/.config/sublime-text-3/Index

Backups don't have a purpose if they're not backed up off site (Dropbox for instance) and if they're not automated (via cronjob):

$ crontab -l
0 0 * * * sh /mnt/D/Dropbox/Linux/backups/backup.sh > /dev/null 2>&1

Outcome:

Picture

Do not forget to occasionally update includes/excludes files to backup/remove new stuff you got in the meantime.