diff options
Diffstat (limited to 'files/sync-backups')
-rw-r--r-- | files/sync-backups | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/files/sync-backups b/files/sync-backups index cb40c77..fc726b3 100644 --- a/files/sync-backups +++ b/files/sync-backups @@ -3,45 +3,62 @@ # sync a removable volume with system backups. # -NODE="$1" -MEDIA="/media/usb" +# Parameters. +BASENAME="`basename $0`" +VOLUME="$1" +MEDIA="/media/$VOLUME" BWLIMIT="2500" IMAGES="/var/data/crypt/" RSYNC="nice -n 19 rsync -avH --delete --bwlimit=$BWLIMIT" -if [ ! -z "$NODE" ]; then - # Get full node hostname. - NODE_HOSTNAME="`cat /var/vservers/$NODE/etc/hostname`" - if [ -z "$NODE_HOSTNAME" ]; then - NODE_HOSTNAME="$NODE" - fi +# Sync backups for a node. +function sync_backups_node { + if [ ! -z "$NODE" ]; then + # Get full node hostname. + NODE_HOSTNAME="`cat /var/vservers/$NODE/etc/hostname`" + if [ -z "$NODE_HOSTNAME" ]; then + NODE_HOSTNAME="$NODE" + fi - # Sync local encrypted backup. - mkdir -p /$MEDIA/$NODE_HOSTNAME/duplicity - $RSYNC /var/vservers/$NODE/var/backups/duplicity/ /$MEDIA/$NODE_HOSTNAME/duplicity/ + # Sync local encrypted backup. + mkdir -p /$MEDIA/$NODE_HOSTNAME/duplicity + $RSYNC /var/vservers/$NODE/var/backups/duplicity/ /$MEDIA/$NODE_HOSTNAME/duplicity/ - # Sync remote backups. - for node in `ls /var/vservers/$NODE/var/backups/remote/`; do - mkdir -p /$MEDIA/$NODE_HOSTNAME/remote/$node - $RSYNC /var/vservers/$NODE/var/backups/remote/$node/ /$MEDIA/$NODE_HOSTNAME/remote/$node/ - done -else - # Sync local encrypted backup. - mkdir -p /$MEDIA/$HOSTNAME/duplicity - $RSYNC /var/backups/duplicity/ /$MEDIA/$HOSTNAME/duplicity/ - - # Sync remote backups. - for node in `ls /var/backups/remote/`; do - mkdir -p /$MEDIA/$HOSTNAME/remote/$node/ - $RSYNC /var/backups/remote/$node/ /$MEDIA/$HOSTNAME/remote/$node/ - done - - # Copy encrypted images. - if [ -d "$IMAGES" ]; then - for image in `find $IMAGES -type f`; do - mkdir -p /$MEDIA/$HOSTNAME/images/`dirname $image` - echo "Copying image to /$MEDIA/$HOSTNAME/images/`dirname $image`" - cp $image /$MEDIA/$HOSTNAME/images/`dirname $image` + # Sync remote backups. + for node in `ls /var/vservers/$NODE/var/backups/remote/`; do + mkdir -p /$MEDIA/$NODE_HOSTNAME/remote/$node + $RSYNC /var/vservers/$NODE/var/backups/remote/$node/ /$MEDIA/$NODE_HOSTNAME/remote/$node/ + done + else + # Sync local encrypted backup. + mkdir -p /$MEDIA/$HOSTNAME/duplicity + $RSYNC /var/backups/duplicity/ /$MEDIA/$HOSTNAME/duplicity/ + + # Sync remote backups. + for node in `ls /var/backups/remote/`; do + mkdir -p /$MEDIA/$HOSTNAME/remote/$node/ + $RSYNC /var/backups/remote/$node/ /$MEDIA/$HOSTNAME/remote/$node/ done + + # Copy encrypted images. + if [ -d "$IMAGES" ]; then + for image in `find $IMAGES -type f`; do + mkdir -p /$MEDIA/$HOSTNAME/images/`dirname $image` + echo "Copying image to /$MEDIA/$HOSTNAME/images/`dirname $image`" + cp $image /$MEDIA/$HOSTNAME/images/`dirname $image` + done + fi fi +} + +# Parsing. +if [ -z "$VOLUME" ]; then + echo "usage: $BASENAME <media> [nodes]" +else + shift fi + +# Sync backups for each node. +for NODE in $*; do + sync_backups_node +done |