SLACKWAY !

Rsync automation

Here is a shell script that can be used for incremental backups:

-------------------------------------------------------------------------------------------------------------------

#!/bin/sh

#########################################################
# Script to do incremental rsync backups
# Adapted from script found on the rsync.samba.org
# Brian Hone 3/24/2002
# This script is freely distributed under the GPL
#########################################################

##################################
# Configure These Options
##################################

###################################
# mail address for status updates
# - This is used to email you a status report
###################################
MAILADDR=your_mail_address_here

###################################
# HOSTNAME
# - This is also used for reporting
###################################
HOSTNAME=your_hostname_here

###################################
# directory to backup
# - This is the path to the directory you want to archive
###################################
BACKUPDIR=directory_you_want_to_backup

###################################
# 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

###################################
# root directory to for backup stuff
###################################
ARCHIVEROOT=directory_to_backup_to

#########################################
# 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`

# options to pass to rsync
OPTIONS="--force --ignore-errors --delete --delete-excluded \
--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

-------------------------------------------------------------------------------------------------------------------

<>The custom rsync script is delimited by dashed lines which are not part of it. You can copy the script to a file and make it executable on your system by doing: chmod+x <file_name>


Full Backup with rsync


The disaster revovery assumes that a full rsync of your system exists on a remote machine or an external media ...

Full backups with rsync should exclude /tmp /mnt /proc

   
    run rsync as follow:    rsync -avl  / <user>@<remote>/<dir> --exclude /tmp /mnt /proc

                                        or

    over ssh with:            rsync -avl --exclude /tmp /mnt /proc -e "ssh"

    example= rsync -av / root@192.168.123.253/mnt/rsync/srv1 --exclude /tmp /mnt /proc

   

Disaster Recovery with rsync


1. Boot with Knoppix.
2. Create partitions with fdisk (or the utility of your choice).
3. Make filesystems, run mkswap, etc.
4. Mount partitions appropriately.
5. Run something like: rsync -zav -e ssh oldhost:/ /mnt
(FYI, I almost always botch the syntax the first try)
6. Make changes as appropriate for new system (/etc/fstab,
/etc/sysconfig/network and /etc/sysconfig/network-scripts/ifcfg-*,
/etc/hosts, and so on).
7. Run grub to install the boot loader
8. Reboot. If it boots, do a quick check to make sure all the partitions
are started, swap has been turned on, etc.

Test this procedure before considering your are safe now.


Cloning a system

For instructions on how to clone a fulle system, see the cloning page.