1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00

feat: Add manual backup and restore scripts for docker (#386)

Closes #128
This commit is contained in:
Valentin 2023-01-17 20:16:50 +01:00 committed by GitHub
parent ddc523f6c9
commit c2d1ca8eeb
3 changed files with 115 additions and 0 deletions

View file

@ -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. 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 ## Development
Clone the repository and install dependencies: Clone the repository and install dependencies:

44
backup.sh Normal file
View file

@ -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!"

37
restore.sh Normal file
View file

@ -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!"