Created
March 5, 2013 18:10
-
-
Save aortbals/5092622 to your computer and use it in GitHub Desktop.
Time machine backup via rsync for any unix machine.
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 | |
# Title: rsync_time_machine.sh | |
# Description: Time machine backup via rsync for any unix machine | |
# Usage: | |
# | |
# - Set the following variables: | |
# `HOME`: the home directory on the local machine to be backed up | |
# `HOST`: the SSH destination to send the backup to | |
# `REMOTEBACKUPDIR`: the location on the remote destination to store the backup | |
# | |
# - Setup SSH keys for automatic login from the local server to the remote server via | |
# [ssh keys](http://linuxproblem.org/art_9.html) | |
# | |
# - Setup a cronjob to run your backup automatically. An example: | |
# # On the 1st and 15th of the month, at 4AM, backup via rsync_time_machine.sh | |
# 0 4 1,15 * * sh /home/localuser/scripts/rsync_time_machine.sh >> /home/localuser/logs/rsync_time_machine_backup.log | |
# | |
# - Create a `~/.rsync/exclude`, Include at least these directories and any large files to ignore: | |
# | |
# /proc | |
# /sys | |
# /lost+found | |
# /mnt | |
# /tmp | |
# | |
# Credits to: http://blog.interlinked.org/tutorials/rsync_time_machine.html | |
date=`date "+%Y%m%d-%H%M"` | |
HOME=/home/localuser | |
[email protected] | |
REMOTEBACKUPDIR=/media/somedrive/remote_snapshots | |
SOURCE="/" # Backup the entire OS | |
PREVIOUSBACKUP="$REMOTEBACKUPDIR/current" | |
CURRENTBACKUP="$REMOTEBACKUPDIR/snapshot-$date" | |
CURRENTINCOMPLETEBACKUP="$REMOTEBACKUPDIR/incomplete_snapshot-$date" | |
EXCLUDEFILE=$HOME/.rsync/exclude | |
rsync -azPE -e ssh --delete --delete-excluded \ | |
--exclude-from=$EXCLUDEFILE \ | |
--link-dest=$PREVIOUSBACKUP $SOURCE $HOST:$CURRENTINCOMPLETEBACKUP \ | |
&& ssh $HOST "mv $CURRENTINCOMPLETEBACKUP $CURRENTBACKUP \ | |
&& rm -f $PREVIOUSBACKUP \ | |
&& ln -s $CURRENTBACKUP $REMOTEBACKUPDIR/current" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment