From: root Date: Thu, 1 Oct 2015 23:40:45 +0000 (+0000) Subject: initial checkin of backup project X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1886f8c05a4588aef021fec4c9868a955d4e8040;p=outofuni%2Fbackup.git initial checkin of backup project --- 1886f8c05a4588aef021fec4c9868a955d4e8040 diff --git a/bin/backup b/bin/backup new file mode 100755 index 0000000..f69dfa0 --- /dev/null +++ b/bin/backup @@ -0,0 +1,84 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo usage: $0 configfile + exit -1 +fi + +if [ ! -f $1 ]; then + echo configfile $1 is not a file + exit -2 +fi + +config=$1 + +host=`grep ^host $config | cut -d ' ' -f 2` +user=`grep ^user $config | cut -d ' ' -f 2` +homedirs="` grep ^homedirs $config | cut -d ' ' -f 2-`" +extradirs="`grep ^extradirs $config | cut -d ' ' -f 2-`" +replicas=`grep ^replicas $config | cut -d ' ' -f 2` +oldest=`grep ^oldest $config | cut -d ' ' -f 2` +data=`grep ^data $config | cut -d ' ' -f 2` +bandwidth=`grep ^bandwidth $config | cut -d ' ' -f 2` + +ping -c1 $host > /dev/null 2>&1 +ret=$? + +if [ "$ret" = "0" ]; then + echo "host $host is online ..." +else + echo "host $host unreachable ..." + exit -3 +fi + +if [ ! -d $data ]; then + echo "no data directory ..." + exit -4 +fi + +today=`date -I` +backupdir=$data/${user}_at_${host} + +cbd=$backupdir/$today +mkdir -p $cbd + +rsync="rsync -azR --delete --bwlimit=$bandwidth" + +ob="" +for pb in $backupdir/[0-9]*; do + bdd=`basename $pb` + if [ ! -f $backupdir/.$bdd ]; then + if [ "$pb" != "$cbd" ]; then + rm -rf $cbd + mv $pb $cbd + fi + + rsrc="" + for dir in $homedirs; do + rsrc="$rsrc :/home/$user/$dir" + done + rsrc="`echo $rsrc | sed 's/^\ //'`" + for dir in $extradirs; do + rsrc="$rsrc :$dir" + done + $rsync $user@$host$rsrc $cbd + ret=$? + [ "$ret" != "0" ] && exit -50 + touch $backupdir/.$pb + fi + ob="$ob $pb" +done + +cob=`echo $ob | wc -w` +if [ $cob -gt $replicas ]; then + ((numdel=cob-replicas)) + todel="`echo $ob | cut -d ' ' -f 1-${numdel}`" + echo "to delete: $todel" + #for dirdel in $todel; do + # bdd=`basename $dirdel` + # rm -r $dirdel + # rm $backupdir/$bdd + #done +fi + +exit 0 diff --git a/config/tx2.conf b/config/tx2.conf new file mode 100644 index 0000000..4d950df --- /dev/null +++ b/config/tx2.conf @@ -0,0 +1,8 @@ +host tx2 +user hackbard +homedirs .config bin briefe moritz private projects ssl +extradirs /scratch +replicas 3 +oldest 60 +data /mnt/wd/ext/backups +bandwidth 5m