From 68fd14bc8684aeaa582f25367e40855bff1779bd Mon Sep 17 00:00:00 2001 From: szaimen Date: Sun, 3 Apr 2022 20:46:28 +0200 Subject: [PATCH] improve instance restore for when nextcloud_datadir is set/not set Signed-off-by: szaimen --- Containers/borgbackup/backupscript.sh | 11 +++++++++++ Containers/borgbackup/start.sh | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Containers/borgbackup/backupscript.sh b/Containers/borgbackup/backupscript.sh index ae378635..5c3df113 100644 --- a/Containers/borgbackup/backupscript.sh +++ b/Containers/borgbackup/backupscript.sh @@ -191,6 +191,13 @@ if [ "$BORG_MODE" = restore ]; then # Save current path BORG_LOCATION="$(jq '.borg_backup_host_location' /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json)" + # Save current nextcloud datadir + if grep -q '"nextcloud_datadir":' /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json; then + NEXTCLOUD_DATADIR="$(jq '.nextcloud_datadir' /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json)" + else + NEXTCLOUD_DATADIR='""' + fi + # Restore the configuration file if ! rsync --archive --human-readable -vv \ /tmp/borg/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json \ @@ -212,6 +219,10 @@ if [ "$BORG_MODE" = restore ]; then CONTENTS="$(jq ".password = $AIO_PASSWORD" /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json)" echo -E "${CONTENTS}" > /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json + # Reset the datadir to the one that was used for the restore + CONTENTS="$(jq ".nextcloud_datadir = $NEXTCLOUD_DATADIR" /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json)" + echo -E "${CONTENTS}" > /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/configuration.json + umount /tmp/borg # Inform user diff --git a/Containers/borgbackup/start.sh b/Containers/borgbackup/start.sh index 9b561036..b189a101 100644 --- a/Containers/borgbackup/start.sh +++ b/Containers/borgbackup/start.sh @@ -35,10 +35,8 @@ fi rm -f "/nextcloud_aio_volumes/nextcloud_aio_database_dump/backup-is-running" # Get a list of all available borg archives -set -x borg list "$BORG_BACKUP_DIRECTORY" | grep "nextcloud-aio" | awk -F " " '{print $1","$3,$4}' > "/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/backup_archives.list" chmod +r "/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/backup_archives.list" -set +x if [ -n "$FAILED" ]; then if [ "$BORG_MODE" = backup ]; then