#!/bin/sh
#########################################################
# Script to do incremental rsync backups - locally
#
# Adapted from script found on the rsync.samba.org
# Brian Hone 3/24/2002
#
# Debugged, Corrected, and modified to keep an exact copy
# of the source drive on a second drive rather than creating
# an additonal directory named "main" or incremental directories, and
# set up to use pmount to auto mount 2nd drive without root access by
# Terry L. Kemmerer 2009/06/30
# This script is freely distributed under the GPL
# NOTE: I have # out some of the functions which I did not want to use
# such as "main" and incremental backup. If you want them back, just
# follow the program flow and remove the #'s where applicable. -Terry
#########################################################
##################################
# Configure These Options
##################################
##################################
# For Safety and Security Purposes, Backup Drive is not mounted
# This portion requires pmount and libpmount0.0 to be installed
# Edit-add to /etc/pmount.allow = /dev/sdb3
#
http://ubuntuforums.org/archive/index.php/t-980122.html
# Mount backup drive
pmount /dev/sdb3 /media/disk
###################################
# mail address for status updates
# - This is used to email you a status report
###################################
MAILADDR="wildcard@plains.net"
###################################
# HOSTNAME
# - This is also used for reporting
###################################
HOSTNAME="ispy"
###################################
# directory to backup
# - This is the path to the directory you want to archive
###################################
BACKUPDIR="/home/lucky/"
###################################
# excludes file - contains one wildcard pattern per line of files to exclude
# - This is a rsync exclude file. See the rsync man page and/or the
# example_exclude_file
###################################
# EXCLUDES=example_exclude_file : create this txt file in the same dir as this script
# the below url tells how to set up and use this file
#
http://articles.slicehost.com/2007/1...es-and-folders
EXCLUDES="/home/lucky/scripts/excluded.txt"
###################################
# root directory to backup stuff
###################################
ARCHIVEROOT="/media/disk/lucky"
#########################################
# From here on out, you probably don't #
# want to change anything unless you #
# know what you're doing. #
#########################################
# directory which holds our current datastore
CURRENT=main
# directory which we save incremental changes to
INCREMENTDIR=`date +%Y-%m-%d` # This 'date' file will be written to ARCHIVEROOT
# options to pass to rsync
OPTIONS="--force --ignore-errors --delete --delete-excluded \
--exclude-from=$EXCLUDES -av"
# used to be: --exclude-from=$EXCLUDES --backup --backup-dir=$ARCHIVEROOT/$INCREMENTDIR -av"
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
# make sure our backup tree exists
install -d $ARCHIVEROOT #/$CURRENT
# our actual rsyncing function
do_rsync()
{
rsync $OPTIONS $BACKUPDIR $ARCHIVEROOT # /$CURRENT
}
# our post rsync accounting function
do_accounting()
{
echo "Backup Accounting for Day $INCREMENTDIR on $HOSTNAME:">/tmp/rsync_script_tmpfile
echo >> /tmp/rsync_script_tmpfile
echo "################################################">>/tmp/rsync_script_tmpfile
du -s $ARCHIVEROOT/* >> /tmp/rsync_script_tmpfile
echo "Mail $MAILADDR -s $HOSTNAME Backup Report < /tmp/rsync_script_tmpfile"
mail $MAILADDR -s $HOSTNAME Backup Report < /tmp/rsync_script_tmpfile
echo "rm /tmp/rsync_script_tmpfile"
rm /tmp/rsync_script_tmpfile
}
# some error handling and/or run our backup and accounting
if [ -f $EXCLUDES ]; then
if [ -d $BACKUPDIR ]; then
# now the actual transfer
do_rsync && do_accounting
else
echo "cant find $BACKUPDIR"; exit
fi
else
echo "cant find $EXCLUDES"; exit
fi
##################################
# Un-Mount backup drive
pumount /dev/sdb3
###################################