rsync script: Backup all entries listed by rsync
Posted: Mon Aug 13, 2007 4:47 pm
Here's a small script I wrote for a centralized backup environment.
Example: 4 workstations and 1 server. Each workstation has rsync running as demon, and the server backs up the folder from the clients using rsync.
In order to make this easier and maintenance free, I wrote a small script that queries rsync for a list of folders it is responsible for and synchronizes each "published" entry.
The uncompressed folders in the root of $DEST_DIR are left on purpose to make it easier for rsync to find changes and only transmit deltas.
(Edit on Oct.29th, 2007: Added ability to use hardlink snapshots)
Example: 4 workstations and 1 server. Each workstation has rsync running as demon, and the server backs up the folder from the clients using rsync.
In order to make this easier and maintenance free, I wrote a small script that queries rsync for a list of folders it is responsible for and synchronizes each "published" entry.
Code: Select all
#!/bin/bash
# @author: ^Rooker
# @date: 13.Aug.2007
# @description: Gets a list of published rsync entries from a client, retrieves all of them and finally compresses each one - or makes a hardlink copy (my favorite).
RSYNC="/usr/bin/rsync"
RSYNC_PORT=873
RSYNC_HOST="to-be-backed-up.mydomain.com"
RSYNC_GET_LIST="$RSYNC --port $RSYNC_PORT $RSYNC_HOST::"
DEST_DIR="/here/is/my/backup/folder"
OLD_DIR=`pwd`
TIMESTAMP=`date +%Y%m%d_%H%M`
function get_backup_list
{
# use 'sed' to strip the comment of each rsync entry:
BACKUP_LIST=`$RSYNC_GET_LIST | sed -e 's/\s".*"/ /g'`
}
function pack_service
{
FILENAME="$TIMESTAMP/$1.tar.bz2";
echo "Packing $1 as \"$FILENAME\"..."
mkdir -p $TIMESTAMP
tar -cjf $FILENAME ./$1
}
function make_snapshot
{
SNAPDIR=$TIMESTAMP
mkdir -p $SNAPDIR
cp -al ./$1 $SNAPDIR/
}
function retrieve_services
{
for service in $1; do
echo "Fetching '$service'... ";
$RSYNC -azt --progress --numeric-ids --delete --timeout=600 --port $RSYNC_PORT $RSYNC_HOST::$service ./$service
#pack_service $service
make_snapshot $service
done
}
cd $DEST_DIR
get_backup_list
retrieve_services "$BACKUP_LIST"
cd $OLD_DIR
The uncompressed folders in the root of $DEST_DIR are left on purpose to make it easier for rsync to find changes and only transmit deltas.
(Edit on Oct.29th, 2007: Added ability to use hardlink snapshots)