From b5d5b1f4bcd42417151c2716e6a3d13ef3ef1d29 Mon Sep 17 00:00:00 2001 From: szaimen Date: Tue, 7 Jun 2022 01:06:47 +0200 Subject: [PATCH] allow to lock the backup archive for external scripts Signed-off-by: szaimen --- Containers/borgbackup/backupscript.sh | 7 +++++++ readme.md | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Containers/borgbackup/backupscript.sh b/Containers/borgbackup/backupscript.sh index ecbd201f..8bdf0556 100644 --- a/Containers/borgbackup/backupscript.sh +++ b/Containers/borgbackup/backupscript.sh @@ -37,6 +37,13 @@ if [ "$BORG_MODE" != backup ] && [ "$BORG_MODE" != test ] && ! [ -f "$BORG_BACKU exit 1 fi +# Do not continue if this file exists (needed for simple external blocking) +if [ -f "$BORG_BACKUP_DIRECTORY/aio-lockfile" ]; then + echo "Not continuing because aio-lockfile exists - it seems like a script is externally running which is locking the backup archive." + echo "If this should not be the case, you can fix this by deleting the 'aio-lockfile' file from the backup archive directory." + exit 1 +fi + # Create lockfile if [ "$BORG_MODE" = backup ] || [ "$BORG_MODE" = restore ]; then touch "/nextcloud_aio_volumes/nextcloud_aio_database_dump/backup-is-running" diff --git a/readme.md b/readme.md index c9ef32d0..39961fa2 100644 --- a/readme.md +++ b/readme.md @@ -293,11 +293,21 @@ if ! [ -d "$TARGET_DIRECTORY" ]; then exit 1 fi +if [ -f "$SOURCE_DIRECTORY/aio-lockfile" ]; then + echo "Not continuing because aio-lockfile already exists." + exit 1 +fi + +touch "$SOURCE_DIRECTORY/aio-lockfile" + if ! rsync --stats --archive --human-readable --delete "$SOURCE_DIRECTORY/" "$TARGET_DIRECTORY"; then echo "Failed to sync the backup repository to the target directory." exit 1 fi +rm "$SOURCE_DIRECTORY/aio-lockfile" +rm "$TARGET_DIRECTORY/aio-lockfile" + umount "$DRIVE_MOUNTPOINT" if docker ps --format "{{.Names}}" | grep "^nextcloud-aio-nextcloud$"; then @@ -317,8 +327,6 @@ Afterwards apply the correct permissions with `sudo chown root:root /root/backup 1. Add the following new line to the crontab if not already present: `0 20 * * 7 /root/backup-script.sh` which will run the script at 20:00 on Sundays each week. 1. save and close the crontab (when using nano are the shortcuts for this `Ctrl + o` -> `Enter` and close the editor with `Ctrl + x`). -⚠️ **Attention:** Make sure that the execution of the script does not collide with the daily backups from AIO (if configured) since the target backup repository might get into an inconsistent state. (There is no check in place that checks this.) - ### How to change the default location of Nextcloud's Datadir? You can configure the Nextcloud container to use a specific directory on your host as data directory. You can do so by adding the environmental variable `NEXTCLOUD_DATADIR` to the initial startup of the mastercontainer. Allowed values for that variable are strings that start with `/` and are not equal to `/`.