From: mwolson_admin Date: Sat, 2 Feb 2008 19:20:31 +0000 (-0500) Subject: hcoop-backup: Overhaul for bandwidth limiting. X-Git-Url: https://git.hcoop.net/hcoop/scripts.git/commitdiff_plain/bee5bcbc0dfcf6365867863579bed840766c84d4 hcoop-backup: Overhaul for bandwidth limiting. * scripts/hcoop-backup: (BWLIMIT): New var indicating KB/s bandwidth limiting to enforce. (BACKUPTMP): Place backups here individually on local disk before transferring offsite. Make this the current directory rather than the offsite AFS directory. (copy_over): New convenience function that copies a file from the local backup location to the offsite location, removing the original. (complain): Make complaint email come from "The Backup Program". --- diff --git a/hcoop-backup b/hcoop-backup index 2dd4332..1d4cff2 100755 --- a/hcoop-backup +++ b/hcoop-backup @@ -15,19 +15,41 @@ PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin #COMPRESS_PROG=bzip2 COMPRESS_EXT=.gz COMPRESS_PROG=gzip +BWLIMIT=250 +# units for BWLIMIT are KB/s IFS=$'\n' KEYFILE=/etc/backup-encryption-key -BACKUPDIR=/afs/megacz.com/private/hcoop-backup/ +BACKUPDIR=/afs/megacz.com/private/hcoop-backup +BACKUPTMP=/var/backups/hcoop-backup +SUBDIR=`date +%Y.%m.%d` + +#SYNC_CMD="rsync --bwlimit=$BWLIMIT --remove-source-files" + +function copy_over () { + # Move file to its offsite destination + # $1: file, $2: relative directory (optional) + if test -z "$1" || test -n "$3"; then + echo "Bad programming" + exit 1 + fi + local FILE=$1 + local DEST=$BACKUPDIR/$SUBDIR + if test -n "$2"; then + DEST=$DEST/$2 + fi + cat $FILE | catsync -b $BWLIMIT $DEST/$FILE + rm -f $FILE +} cd $BACKUPDIR find * -prune -ctime +2 -exec rm -rf {} \; || true -SUBDIR=`date +%Y.%m.%d` rm -rf $SUBDIR mkdir -p $SUBDIR -cd $SUBDIR +mkdir -p $BACKUPTMP +cd $BACKUPTMP groups echo 'I am in:' @@ -38,7 +60,8 @@ echo building package lists... dpkg-query -W -f='${Package}\n' > packages (cd /; find / /usr/ /usr/local/ /var/ -xdev) | sort | uniq > allfiles dpkg-query -W -f='${Package}\n' | xargs dpkg -L | sort | uniq > debfiles -dpkg-query -W -f='${Conffiles}\n' | grep / | cut -b2- | sed 's_ .*__' | sort | uniq > conffiles +dpkg-query -W -f='${Conffiles}\n' | grep / | cut -b2- | \ + sed 's_ .*__' | sort | uniq > conffiles diff allfiles debfiles | grep '^<' | cut -b 3- | \ grep -v ^/var/cache | \ @@ -98,14 +121,13 @@ cat backupfiles | \ grep -v ^/var/lib/mysql/ | \ grep -v ^/var/lib/postgres/ | \ grep -v ^/var/lib/postgresql/ | \ - xargs -I{} -d\\n -- bash -c "test -L '{}' || echo '{}'" | \ - cat > complain + xargs -I{} -d\\n -- bash -c "test -L '{}' || echo '{}'" > complain +F=hcoop.backup.tar$COMPRESS_EXT.aescrypt tar clpf - --ignore-failed-read --no-recursion -C / -T backupfiles | \ $COMPRESS_PROG | \ - ccrypt -k $KEYFILE -e | \ - catsync hcoop.backup.tar$COMPRESS_EXT.aescrypt - + ccrypt -k $KEYFILE -e > $F +copy_over $F # Acquire lock before messing with spamd COUNT=0 @@ -123,15 +145,15 @@ while test -f $LOCK; do done touch $LOCK +F=common.spamd.tar$COMPRESS_EXT.aescrypt tar clpf - --ignore-failed-read -C / /var/local/lib/spamd | \ $COMPRESS_PROG | \ - ccrypt -k $KEYFILE -e | \ - catsync ../common.spamd.tar$COMPRESS_EXT.aescrypt.new + ccrypt -k $KEYFILE -e > $F.new rm -f $LOCK +copy_over $F.new .. -test -s ../common.spamd.tar$COMPRESS_EXT.aescrypt.new && \ - mv ../common.spamd.tar$COMPRESS_EXT.aescrypt.new \ - ../common.spamd.tar$COMPRESS_EXT.aescrypt +test -s $BACKUPDIR/$F.new && \ + mv $BACKUPDIR/$F.new $BACKUPDIR/$F vos listvol deleuze | \ tail -n +2 | \ @@ -148,16 +170,21 @@ cat volumes | \ grep -v not-backed-up | \ xargs -I{} -d\\n -- \ bash -c \ - "vos dump -id {} -localauth -clone | $COMPRESS_PROG | ccrypt -k $KEYFILE -e | catsync {}.dump$COMPRESS_EXT.aescrypt" + "F={}.dump$COMPRESS_EXT.aescrypt ; + vos dump -id {} -localauth -clone | + $COMPRESS_PROG | ccrypt -k $KEYFILE -e > \$F ; + cat \$F | catsync -b $BWLIMIT $BACKUPDIR/$SUBDIR/\$F ; + rm -f \$F" echo backing up databases +F=databases.tar$COMPRESS_EXT.aescrypt tar -C /var/backups/databases/ -cf - . | \ $COMPRESS_PROG | \ - ccrypt -k $KEYFILE -e \ - | catsync databases.tar$COMPRESS_EXT.aescrypt + ccrypt -k $KEYFILE -e > $F +copy_over $F grep '[a-z/]' complain && \ - mail -a 'From: Adam Megacz ' \ + mail -a 'From: The Backup Program ' \ -s "automated message: annoying files found on deleuze (please do something about them)" admins@hcoop.net \ < complain \ || true