]> hackdaworld.org Git - outofuni/backup.git/commitdiff
initial checkin of backup project
authorroot <root@beagle.fritz.box>
Thu, 1 Oct 2015 23:40:45 +0000 (23:40 +0000)
committerroot <root@beagle.fritz.box>
Thu, 1 Oct 2015 23:40:45 +0000 (23:40 +0000)
bin/backup [new file with mode: 0755]
config/tx2.conf [new file with mode: 0644]

diff --git a/bin/backup b/bin/backup
new file mode 100755 (executable)
index 0000000..f69dfa0
--- /dev/null
@@ -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 (file)
index 0000000..4d950df
--- /dev/null
@@ -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