Skip to content

Instantly share code, notes, and snippets.

@DimensionalScoop
Created August 4, 2015 13:43
Show Gist options
  • Save DimensionalScoop/8bf022c27b9c073e7077 to your computer and use it in GitHub Desktop.
Save DimensionalScoop/8bf022c27b9c073e7077 to your computer and use it in GitHub Desktop.
My rsync backup script
#!/bin/bash
if [ "$(whoami)" != "root" ]; then
echo "You should be root to run backup."
fi
backupSource="/home/elayn/"
backupTarget="/run/media/elayn/Jet Black/Backup/Rsync-LinuxHome/" #the dir where the backup is saved
now=$(date +"%Y-%m-%d-%H%M") # name of this backup
snapshot="$backupTarget/$now"
cd "$backupTarget"
lastBackup=$(ls | tail -1) # ls prints dirs in alphabetical order, so the last entry should be the most current backup, if it exists
mkdir "$snapshot"
if [ "$lastBackup" == "" ]; then
echo "No previous backups found, creating master..."
rsync --archive --acls --xattrs --hard-links --verbose --compress --exclude={"/home/*/.thumbnails/*","/home/*/.cache/mozilla/*","/home/*/.cache/chromium/*","/home/*/.local/share/Trash/*","/home/*/.gvfs"} "$backupSource" "$snapshot" &> "$snapshot/rsync.log"
elif [ "$lastBackup" != "" ]; then
echo "Using $lastBackup as template..."
rsync --archive --acls --xattrs --hard-links --verbose --compress --exclude={"/home/*/.thumbnails/*","/home/*/.cache/mozilla/*","/home/*/.cache/chromium/*","/home/*/.local/share/Trash/*","/home/*/.gvfs"} --link-dest "$backupTarget/$lastBackup" "$backupSource" "$snapshot" &> "$snapshot/rsync.log"
fi
tail "$snapshot/rsync.log"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment