diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2010-08-21 18:37:48 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2010-08-21 18:37:48 -0300 |
commit | 7f075c1e3e99dc42bec414aa071c9e2fb5da0ded (patch) | |
tree | 21a4ae398ae77442fe3c14d0d004086b1b3d92b1 /handlers/rsync.in | |
parent | 9fe6ebf3777e4c03d79d824def69ac7b67783c03 (diff) | |
download | backupninja-7f075c1e3e99dc42bec414aa071c9e2fb5da0ded.tar.gz backupninja-7f075c1e3e99dc42bec414aa071c9e2fb5da0ded.tar.bz2 |
Fixing lockfile checks for rsync handler
Diffstat (limited to 'handlers/rsync.in')
-rw-r--r-- | handlers/rsync.in | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/handlers/rsync.in b/handlers/rsync.in index 21e4ab2..cf304ed 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -847,7 +847,13 @@ function test_connect { function set_lockfile { if [ ! -z "$lockfile" ]; then - $touch $lockfile || warning "Could not create lockfile $lockfile" + mkdir -p `dirname $lockfile` + if ( set -o noclobber; echo "$$" > "$lockfile" ) &> /dev/null; then + trap 'rm -f "$lockfile"' INT TERM EXIT + else + info "Could not create lockfile $lockfile, exiting" + exit + fi fi } @@ -860,6 +866,23 @@ function unset_lockfile { } +function check_lockfile { + + local pid + + if [ ! -z "$lockfile" ] && [ -f "$lockfile" ]; then + pid="`cat $lockfile`" + if ps $pid &> /dev/null; then + info "Another backup is running for $lockfile, skipping run" + exit + else + info "Found old lockfile $lockfile, removing it" + unset_lockfile + fi + fi + +} + function set_filelist { filelist_flag="" @@ -1045,6 +1068,7 @@ function end_mux { # the backup procedure eval_config +check_lockfile set_lockfile set_rsync_options start_mux |