Created
August 4, 2015 13:43
-
-
Save DimensionalScoop/8bf022c27b9c073e7077 to your computer and use it in GitHub Desktop.
My rsync backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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