From 5df8dba25cb438719cfa40a22cb75d156466f9a7 Mon Sep 17 00:00:00 2001 From: Magnus Andersson Date: Thu, 12 Oct 2023 08:59:17 +0200 Subject: [PATCH] backup-all-buckets: Safeguard backup runs if a backup process on that bucket is already in progress. --- templates/script/backup-all-buckets.erb.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/script/backup-all-buckets.erb.sh b/templates/script/backup-all-buckets.erb.sh index 9ded804..66c909f 100644 --- a/templates/script/backup-all-buckets.erb.sh +++ b/templates/script/backup-all-buckets.erb.sh @@ -36,15 +36,17 @@ function do_backup { local bucket="${3}" local mirrorbucket="${bucket}-mirror" local mountpoint="/opt/backupmounts/${bucket}" + ps aux | grep duplicity | grep "[^a-zA-Z]${bucket}" > /dev/null + local oktorun=$? mkdir -p ${mountpoint} - rclone mount ${project}:${bucket} ${mountpoint}/ --daemon --allow-other --dir-cache-time 24h + [ ${oktorun} -ne 0 ] && rclone mount ${project}:${bucket} ${mountpoint}/ --daemon --allow-other --dir-cache-time 24h rclone mkdir ${mirror}:${mirrorbucket} - duplicity --full-if-older-than 1M --asynchronous-upload --tempdir /mnt --archive-dir /mnt \ + [ ${oktorun} -ne 0 ] && duplicity --full-if-older-than 1M --asynchronous-upload --tempdir /mnt --archive-dir /mnt \ --no-encryption ${mountpoint} rclone://${mirror}:/${mirrorbucket} umount ${mountpoint} rmdir ${mountpoint} # Clean up - duplicity remove-all-but-n-full ${number_of_full_to_keep} --tempdir /mnt --archive-dir /mnt \ + [ ${oktorun} -ne 0 ] && duplicity remove-all-but-n-full ${number_of_full_to_keep} --tempdir /mnt --archive-dir /mnt \ --force rclone://${mirror}:/${mirrorbucket} }