Hello, currently I am using rsync in a shell script to do incremental backups of a couple of systems. I know, it isn't glamorous, and can be done in much better ways, but I am trying to keep it simple, and not have to force myself to learn to program in the next... year, just to keep up. Anyways...
I am using a fairly common script online, and I modified it a bit, just to satisfy my anal-retentiveness, and make it a bit easier to decipher. The script is as follows:
#! /bin/bash
#
################################################## #################
# This is a script to run my backups. Put together from sources all over the 'net, it will, #
# in theory, wake up the remote server, perform an rsync-style incremental backup, then shut #
# the the server down. This script is a modified version of one found in an article of Linux #
# Journal in Jan 06 titled 'Build a Home Terabyte Backup System'. I am not sure who the ## author was, but their script was a modified version of one created by rsync creator Andrew #
# Tridgell. #
################################################## #################
###########
# VARIABLES #
# Login name
LOGIN=ron
# Backup server name
BUSRVR=backups
# Backup server MAC address
BUMAC=xx:xx:xx:xx:xx
# Directory to be backed up
BUSRC=/home/ron/test/
# Directory on server to back up to
BUDEST=/backups/ron/rsync.test
# This is the backup subdirectory, dictated by date and time
BUSUBDIR=`date +%A`
# Log file location
LOGLOCATION=/home/ron/Desktop
# Options to pass to rsync
OPTS="--delete -vv --modify-window=2 --force --ignore-errors --backup --backup-dir=$BUDEST/ -az --stats --partial-dir=RSYNC.PARTIAL --progress -e ssh"
###########
# Commands #
###########
# Dump output to log
date > $LOGLOCATION/backuplog.$BUSUBDIR.txt
# Wake up the remote server
sudo /usr/local/bin/ether-wake $BUMAC
# Wait an amount of time to allow the server to boot and get ready for data transfer
sleep 180
# This section deletes the last week's incremental backups
[ -d /tmp/emptydir ] || mkdir /tmp/emptydir
rsync --delete -a /tmp/emptydir
$LOGIN@$BUSRVR:$BUDEST/$BUSUBDIR/
rmdir /tmp/emptydir
# Actual file transfer
rsync $OPTS $BUSRC $LOGIN@$BUSRVR:$BUDEST/current >> $LOGLOCATION/backuplog.$BUSUBDIR.txt
Can someone please explain to me how the Bold/Underlined part works? When I run the script, it does run and creates a subdirectory for 'current' and copies all source files over as it should. But when it runs the increment, it will create a another directory for the day of the week, then run a full backup to it, instead of an increment. I am just not seeing how '-d /tmp... ' is a command and can actually do something. I am a rookie to scripting though (and Linux in general, having only dealt with it for about a year). Any help would be greatly appreciated.


Reply With Quote
Bookmarks