aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2012-05-12 11:00:35 -0300
committerSilvio Rhatto <rhatto@riseup.net>2012-05-12 11:00:35 -0300
commitad57dc60774ba62a8cd2a76feb1f24ba15e01e23 (patch)
tree6ce495a010aaabd2b07a4bc1bc6b64d73fe9b213
parent6f0cc20d21d8d48899ef31a3164a0da75b78b232 (diff)
downloadpuppet-backup-ad57dc60774ba62a8cd2a76feb1f24ba15e01e23.tar.gz
puppet-backup-ad57dc60774ba62a8cd2a76feb1f24ba15e01e23.tar.bz2
Adding back lockfile code on rsync handler
-rw-r--r--files/handlers/rsync44
1 files changed, 44 insertions, 0 deletions
diff --git a/files/handlers/rsync b/files/handlers/rsync
index 01a2987..cb4db46 100644
--- a/files/handlers/rsync
+++ b/files/handlers/rsync
@@ -39,6 +39,7 @@
# keepdaily = for long storage format, specify the number of daily backup increments
# keepweekly = for long storage format, specify the number of weekly backup increments
# keepmonthly = for long storage format, specify the number of monthly backup increments
+# lockfile = lockfile to be kept during backup execution
# nicelevel = rsync command nice level
# enable_mv_timestamp_bug = set to "yes" if your system isnt handling timestamps correctly
# tmp = temp folder
@@ -128,6 +129,7 @@ function eval_config {
getconf keepdaily 5
getconf keepweekly 3
getconf keepmonthly 1
+ getconf lockfile
getconf nicelevel 0
getconf enable_mv_timestamp_bug no
getconf tmp /tmp
@@ -892,6 +894,45 @@ function test_connect {
}
+function set_lockfile {
+
+ if [ ! -z "$lockfile" ]; then
+ mkdir -p `dirname $lockfile`
+ if ( set -o noclobber; echo "$$" > "$lockfile" ) &> /dev/null; then
+ trap 'unset_lockfile' INT TERM EXIT
+ else
+ fatal "Could not create lockfile $lockfile, exiting"
+ fi
+ fi
+
+}
+
+function unset_lockfile {
+
+ if [ ! -z "$lockfile" ]; then
+ $rm -f $lockfile || warning "Could not remove lockfile $lockfile"
+ fi
+
+}
+
+function check_lockfile {
+
+ local pid process
+
+ if [ ! -z "$lockfile" ] && [ -f "$lockfile" ]; then
+ pid="`cat $lockfile`"
+ process="`ps --no-headers -o comm $pid`"
+ if [ "$?" == "0" ] && [ "`ps --no-headers -o comm $$`" == "$process" ]; 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=""
@@ -1103,6 +1144,8 @@ function restore_pipefail {
# the backup procedure
eval_config
+check_lockfile
+set_lockfile
set_rsync_options
start_mux
stop_services
@@ -1136,6 +1179,7 @@ restore_pipefail
mount_ro
run_fsck
start_services
+unset_lockfile
end_mux
echo "Finnishing backup at `date`" >> $log