From: root Date: Thu, 26 Jul 2007 02:22:12 +0000 (+0000) Subject: Now implements locking and catch of SIGINT and SIGTERM X-Git-Url: https://git.sesse.net/?p=backup.sh;a=commitdiff_plain;h=c027e80dd5f2ac433fefeb76dabc4a3f7aed988b Now implements locking and catch of SIGINT and SIGTERM --- diff --git a/backup.sh b/backup.sh index ed089e5..0a4cb4a 100755 --- a/backup.sh +++ b/backup.sh @@ -1,5 +1,22 @@ #!/bin/sh +# Locking +LOCKFILE=/home/backup/backuprun.lockfile + +# Die gracefully (ie. remove lockfile) +die() { + rm $LOCKFILE + exit 255 +} + +trap die SIGINT SIGTERM + +if [ -e $LOCKFILE ]; then + echo `date`": $LOCKFILE exists, exiting." + exit 1 +fi; +touch $LOCKFILE + #dirs confdir=/home/backup/conf/ #configuration files storagedir=/backup #mountpoint of huge disc @@ -200,7 +217,7 @@ do #gå ned i rett katalog, eller dø # TODO bør sende mail om dette skjer! - cd $storagedir/$computer/$sfilesystem/$backuplevel || exit 1 + cd $storagedir/$computer/$sfilesystem/$backuplevel || die #perform the actual backup backup @@ -239,14 +256,9 @@ done & wait -#create report -# (Hasn't been working for years -berge) -#/home/backup/report.sh $storagedir > /tmp/report.txt -#[ ! -z $remotestat ] && scp /tmp/report.txt $remotestat -### - # print diskusage to logfile echo "Current disk usage:" -df -k +df -k $storagedir echo `date`": Backup run ended" +