From a3f101a1396564465a04a3118274939473c36163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Florczak?= Date: Wed, 27 Nov 2024 11:49:55 +0100 Subject: [PATCH] fix: Quote variables to prevent word splitting (#962) --- docker-backup.sh | 22 +++++++++++----------- docker-restore.sh | 14 +++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docker-backup.sh b/docker-backup.sh index 1bf5cae7..f6909961 100644 --- a/docker-backup.sh +++ b/docker-backup.sh @@ -9,36 +9,36 @@ PLANKA_DOCKER_CONTAINER_PLANKA="planka_planka_1" # Create Temporary folder BACKUP_DATETIME=$(date --utc +%FT%H-%M-%SZ) -mkdir -p $BACKUP_DATETIME-backup +mkdir -p "$BACKUP_DATETIME-backup" # Dump DB into SQL File echo -n "Exporting postgres database ... " -docker exec -t $PLANKA_DOCKER_CONTAINER_POSTGRES pg_dumpall -c -U postgres > $BACKUP_DATETIME-backup/postgres.sql +docker exec -t "$PLANKA_DOCKER_CONTAINER_POSTGRES" pg_dumpall -c -U postgres > "$BACKUP_DATETIME-backup/postgres.sql" echo "Success!" # Export Docker Voumes echo -n "Exporting user-avatars ... " -docker run --rm --volumes-from $PLANKA_DOCKER_CONTAINER_PLANKA -v $(pwd)/$BACKUP_DATETIME-backup:/backup ubuntu cp -r /app/public/user-avatars /backup/user-avatars +docker run --rm --volumes-from "$PLANKA_DOCKER_CONTAINER_PLANKA" -v "$(pwd)/$BACKUP_DATETIME-backup:/backup" ubuntu cp -r /app/public/user-avatars /backup/user-avatars echo "Success!" echo -n "Exporting project-background-images ... " -docker run --rm --volumes-from $PLANKA_DOCKER_CONTAINER_PLANKA -v $(pwd)/$BACKUP_DATETIME-backup:/backup ubuntu cp -r /app/public/project-background-images /backup/project-background-images +docker run --rm --volumes-from "$PLANKA_DOCKER_CONTAINER_PLANKA" -v "$(pwd)/$BACKUP_DATETIME-backup:/backup" ubuntu cp -r /app/public/project-background-images /backup/project-background-images echo "Success!" echo -n "Exporting attachments ... " -docker run --rm --volumes-from $PLANKA_DOCKER_CONTAINER_PLANKA -v $(pwd)/$BACKUP_DATETIME-backup:/backup ubuntu cp -r /app/private/attachments /backup/attachments +docker run --rm --volumes-from "$PLANKA_DOCKER_CONTAINER_PLANKA" -v "$(pwd)/$BACKUP_DATETIME-backup:/backup" ubuntu cp -r /app/private/attachments /backup/attachments echo "Success!" # Create tgz echo -n "Creating final tarball $BACKUP_DATETIME-backup.tgz ... " -tar -czf $BACKUP_DATETIME-backup.tgz \ - $BACKUP_DATETIME-backup/postgres.sql \ - $BACKUP_DATETIME-backup/user-avatars \ - $BACKUP_DATETIME-backup/project-background-images \ - $BACKUP_DATETIME-backup/attachments +tar -czf "$BACKUP_DATETIME-backup.tgz" \ + "$BACKUP_DATETIME-backup/postgres.sql" \ + "$BACKUP_DATETIME-backup/user-avatars" \ + "$BACKUP_DATETIME-backup/project-background-images" \ + "$BACKUP_DATETIME-backup/attachments" echo "Success!" #Remove source files echo -n "Cleaning up temporary files and folders ... " -rm -rf $BACKUP_DATETIME-backup +rm -rf "$BACKUP_DATETIME-backup" echo "Success!" echo "Backup Complete!" diff --git a/docker-restore.sh b/docker-restore.sh index 29ae537d..1b802ceb 100644 --- a/docker-restore.sh +++ b/docker-restore.sh @@ -9,29 +9,29 @@ PLANKA_DOCKER_CONTAINER_PLANKA="planka_planka_1" # Extract tgz archive PLANKA_BACKUP_ARCHIVE_TGZ=$1 -PLANKA_BACKUP_ARCHIVE=$(basename $PLANKA_BACKUP_ARCHIVE_TGZ .tgz) +PLANKA_BACKUP_ARCHIVE=$(basename "$PLANKA_BACKUP_ARCHIVE_TGZ" .tgz) echo -n "Extracting tarball $PLANKA_BACKUP_ARCHIVE_TGZ ... " -tar -xzf $PLANKA_BACKUP_ARCHIVE_TGZ +tar -xzf "$PLANKA_BACKUP_ARCHIVE_TGZ" echo "Success!" # Import Database echo -n "Importing postgres database ... " -cat $PLANKA_BACKUP_ARCHIVE/postgres.sql | docker exec -i $PLANKA_DOCKER_CONTAINER_POSTGRES psql -U postgres +cat "$PLANKA_BACKUP_ARCHIVE/postgres.sql" | docker exec -i "$PLANKA_DOCKER_CONTAINER_POSTGRES" psql -U postgres echo "Success!" # Restore Docker Volumes echo -n "Importing user-avatars ... " -docker run --rm --volumes-from $PLANKA_DOCKER_CONTAINER_PLANKA -v $(pwd)/$PLANKA_BACKUP_ARCHIVE:/backup ubuntu cp -rf /backup/user-avatars /app/public/ +docker run --rm --volumes-from "$PLANKA_DOCKER_CONTAINER_PLANKA" -v "$(pwd)/$PLANKA_BACKUP_ARCHIVE:/backup" ubuntu cp -rf /backup/user-avatars /app/public/ echo "Success!" echo -n "Importing project-background-images ... " -docker run --rm --volumes-from $PLANKA_DOCKER_CONTAINER_PLANKA -v $(pwd)/$PLANKA_BACKUP_ARCHIVE:/backup ubuntu cp -rf /backup/project-background-images /app/public/ +docker run --rm --volumes-from "$PLANKA_DOCKER_CONTAINER_PLANKA" -v "$(pwd)/$PLANKA_BACKUP_ARCHIVE:/backup" ubuntu cp -rf /backup/project-background-images /app/public/ echo "Success!" echo -n "Importing attachments ... " -docker run --rm --volumes-from $PLANKA_DOCKER_CONTAINER_PLANKA -v $(pwd)/$PLANKA_BACKUP_ARCHIVE:/backup ubuntu cp -rf /backup/attachments /app/private/ +docker run --rm --volumes-from "$PLANKA_DOCKER_CONTAINER_PLANKA" -v "$(pwd)/$PLANKA_BACKUP_ARCHIVE:/backup" ubuntu cp -rf /backup/attachments /app/private/ echo "Success!" echo -n "Cleaning up temporary files and folders ... " -rm -r $PLANKA_BACKUP_ARCHIVE +rm -r "$PLANKA_BACKUP_ARCHIVE" echo "Success!" echo "Restore complete!"