CRIBBS -- Cron Rsync Incremental Backup Bash Script

Send Snippet To: Save this snippet to Code Collector Pro -- view all seydoggy's snippets
language: bash
license: Other

Code for Snippet:

                
#!/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
comments powered by Disqus

Info

Tags: cron rsync incremental backup bash cribbs

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 6282
Date Added: 2011-05-27 17:20:32
Last Modified: 0000-00-00 00:00:00

Web Analytics