Skip to content

Instantly share code, notes, and snippets.

@captbrogers
Last active November 5, 2015 13:39
Show Gist options
  • Save captbrogers/86033ef55b488c828c9d to your computer and use it in GitHub Desktop.
Save captbrogers/86033ef55b488c828c9d to your computer and use it in GitHub Desktop.
Rsync for snapshot
#!/bin/bash
# Basic snapshot-style rsync backup script
# Taken from https://wiki.archlinux.org/index.php/Rsync#Snapshot_backup
# Config
## archive, show progress, in human readable sizes
OPT="-aPh"
LINK="--link-dest=/snapshots/username/last/"
SRC="/home/username/"
SNAP="/snapshots/username/"
LAST="/snapshots/username/last"
date=`date "+%Y-%b-%d:_%T"`
EXCLUDE="--exclude='rsync-exclude.txt' --exclude-from 'rsync-exclude.txt'"
# Run rsync to create snapshot
rsync $OPT $LINK $EXCLUDE $SRC ${SNAP}$date
# Remove symlink to previous snapshot
rm -f $LAST
# Create new symlink to latest snapshot for the next backup to hardlink
ln -s ${SNAP}$date $LAST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment