Created
August 14, 2013 17:24
-
-
Save seyDoggy/6233280 to your computer and use it in GitHub Desktop.
I wrote this a long time ago. I've since moved on. But for posterity I've moved it off codecollector.net.
This file contains hidden or 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 | |
####################################################### | |
# CRIBBS -- Cron Rsync Incremental Backup Bash Script # | |
# AUTHOR: Adam Merrifield <http://adam.merrifield.ca> # | |
# (and countless sources from the web) # | |
# DATE: 05-26-11 23:17 # | |
# VERSION: 1.0.0 # | |
####################################################### | |
################## | |
## INSTRUCTIONS ## | |
################## | |
# You'll need: | |
# - a remote server running rsync | |
# - the ability to create an ssh key pair | |
# between here and there | |
# - time | |
# - patience | |
# Step 1: read up on the stuff you don't know. | |
# Step 2: establish an ssh public key pair with your server | |
# Step 3: save this script as a .sh or .command file | |
# someplace on your computer | |
# Step 4: edit the variables accordingly and save | |
# Step 5: establish a cron job with this saved file | |
# Step 6: bask in the glory of CRIBBS | |
########## | |
## HELP ## | |
########## | |
# For rsync help: | |
# http://rsync.samba.org/ftp/rsync/rsync.html | |
# For crontab help: | |
# http://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html | |
# For ssh-keygen help: | |
# http://www.openbsd.org/cgi-bin/man.cgi?query=ssh-keygen&sektion=1 | |
############### | |
## VARIABLES ## | |
############### | |
# [EDIT] Local directory to be backed up | |
# hint: best to include the trailing "/" | |
LPATH=/Users/name/ | |
# [EDIT] Local files and directories to exclude | |
# hint: the exclude file should contain one directory/file per line | |
XPATH=/Users/name/someplace/exclude.file | |
# [EDIT] Local key | |
# hint: must match contents of ~/.ssh/authorized_keys on remote server | |
LKEY=/Users/name/someplace/some-key-name | |
# [EDIT] Remote login name | |
# hint: this would "adam" in [email protected] | |
RUSER=username | |
# [EDIT] Remote backup server name | |
# hint: this would "10.0.1.3" in [email protected] | |
RHOST=servername | |
# [EDIT] Remote directory where you want backups to occur | |
# hint: best to leave off the trailing "/" | |
RBASE=/home/name | |
# [EDIT] rsync options | |
# hint: do not edit unless you know what you're doing | |
ROPT="-azprvP --delete --delete-excluded --exclude-from=$XPATH --modify-window=2 --force --ignore-errors --stats" | |
################# | |
## DO NOT EDIT ## | |
################# | |
# Remote current path to test against | |
RCURRENT=$RBASE/current | |
# date | |
date=`date "+%Y-%m-%d-T%H_%M_%S"` | |
# Remote full progress path | |
RSSHPROGPATH=$RBASE/previous/incomplete_back-$date | |
# Remote full completed path | |
RSSHCOMPPATH=$RBASE/previous/back-$date | |
# Remote login | |
RLOGIN=$RUSER@$RHOST | |
# Remote full rsync path | |
RSYNCPATH=$RLOGIN:$RSSHPROGPATH | |
# Make "previous" directory | |
ssh -i $LKEY $RLOGIN "[ -d $RBASE/previous ] || mkdir $RBASE/previous" | |
# rsync backup command | |
rsync $ROPT -e "ssh -i $LKEY" --link-dest=$RCURRENT $LPATH $RSYNCPATH | |
# shuffle backups around | |
ssh -i $LKEY $RLOGIN mv $RSSHPROGPATH $RSSHCOMPPATH | |
ssh -i $LKEY $RLOGIN rm -f $RCURRENT | |
ssh -i $LKEY $RLOGIN ln -s $RSSHCOMPPATH $RCURRENT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment