From c2d1ca8eebd47fc4a0b71ce2b3b2f8dabf16bb5c Mon Sep 17 00:00:00 2001 From: Valentin Date: Tue, 17 Jan 2023 20:16:50 +0100 Subject: [PATCH] feat: Add manual backup and restore scripts for docker (#386) Closes #128 --- README.md | 34 ++++++++++++++++++++++++++++++++++ backup.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ restore.sh | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 backup.sh create mode 100644 restore.sh diff --git a/README.md b/README.md index 68c15bf8..0ad45792 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,40 @@ fail2ban-client status planka It's already available in Planka, or you can also use the great tool [trello2planka](https://github.com/christophenne/trello2planka) to do the import. +### Backup and Restore + +Planka comes with two scripts that allow for manual backup and restore when running Planka with docker-compose.yml. +Backups can be triggered with `backup.sh` which will export the Database, User Avatars, Project Backgrounds and Attachments into a single tgz file. + +``` +$ ./backup.sh +Exporting postgres database ... Success! +Exporting user-avatars ... Success! +Exporting project-background-images ... Success! +Exporting attachments ... Success! +Creating final tarball 2023-01-17T15-37-22Z-backup.tgz ... Success! +Cleaning up temporary files and folders ... Success! +Backup Complete! +``` + +The resulting backup can be restored using the `restore.sh` script. + +``` +$ ./restore.sh 2023-01-17T15-37-22Z-backup.tgz +Extracting tarball 2023-01-17T11-10-54Z-backup.tgz ... Success! +Importing postgres database ... + +[Many lines of postgres output] +... + +Success! +Importing user-avatars ... Success! +Importing project-background-images ... Success! +Importing attachments ... Success! +Cleaning up temporary files and folders ... Success! +Restore complete! +``` + ## Development Clone the repository and install dependencies: diff --git a/backup.sh b/backup.sh new file mode 100644 index 00000000..1bf5cae7 --- /dev/null +++ b/backup.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Stop on Error +set -e + +# Configure those to match your Planka Docker container names +PLANKA_DOCKER_CONTAINER_POSTGRES="planka_postgres_1" +PLANKA_DOCKER_CONTAINER_PLANKA="planka_planka_1" + +# Create Temporary folder +BACKUP_DATETIME=$(date --utc +%FT%H-%M-%SZ) +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 +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 +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 +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 +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 +echo "Success!" + +#Remove source files +echo -n "Cleaning up temporary files and folders ... " +rm -rf $BACKUP_DATETIME-backup +echo "Success!" + +echo "Backup Complete!" diff --git a/restore.sh b/restore.sh new file mode 100644 index 00000000..29ae537d --- /dev/null +++ b/restore.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Stop on Error +set -e + +# Configure those to match your Planka Docker container names +PLANKA_DOCKER_CONTAINER_POSTGRES="planka_postgres_1" +PLANKA_DOCKER_CONTAINER_PLANKA="planka_planka_1" + +# Extract tgz archive +PLANKA_BACKUP_ARCHIVE_TGZ=$1 +PLANKA_BACKUP_ARCHIVE=$(basename $PLANKA_BACKUP_ARCHIVE_TGZ .tgz) +echo -n "Extracting tarball $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 +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/ +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/ +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/ +echo "Success!" + +echo -n "Cleaning up temporary files and folders ... " +rm -r $PLANKA_BACKUP_ARCHIVE +echo "Success!" + +echo "Restore complete!"