From c783b3425ff2462c15fc182e4edad9e3b08afc66 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 17 Jan 2023 11:03:35 -0500 Subject: [PATCH] Adding a compressed / gzip version for backup and restore. --- src/en/administration/backup_and_restore.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/en/administration/backup_and_restore.md b/src/en/administration/backup_and_restore.md index 190b9b1..3b2ed9c 100644 --- a/src/en/administration/backup_and_restore.md +++ b/src/en/administration/backup_and_restore.md @@ -6,17 +6,18 @@ When using docker or ansible, there should be a `volumes` folder, which contains ### Incremental Database backup -To incrementally backup the DB to an `.sql` file, you can run: +To incrementally backup the DB to an `.sql.gz` file, you can run: ```bash -docker-compose exec postgres pg_dumpall -c -U lemmy > lemmy_dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql +docker-compose exec postgres pg_dumpall -c -U lemmy | gzip > lemmy_dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz ``` + ### A Sample backup script ```bash #!/bin/sh # DB Backup -ssh MY_USER@MY_IP "docker-compose exec postgres pg_dumpall -c -U lemmy" > ~/BACKUP_LOCATION/INSTANCE_NAME_dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql +ssh MY_USER@MY_IP "docker-compose exec postgres pg_dumpall -c -U lemmy" | gzip > ~/BACKUP_LOCATION/INSTANCE_NAME_dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz # Volumes folder Backup rsync -avP -zz --rsync-path="sudo rsync" MY_USER@MY_IP:/LEMMY_LOCATION/volumes ~/BACKUP_LOCATION/FOLDERNAME @@ -30,8 +31,8 @@ If you need to restore from a `pg_dumpall` file, you need to first clear out you # Drop the existing DB docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" -# Restore from the .sql backup -cat db_dump.sql | docker exec -i FOLDERNAME_postgres_1 psql -U lemmy # restores the db +# Restore from the .sql.gz backup +gunzip < db_dump.sql | docker exec -i FOLDERNAME_postgres_1 psql -U lemmy # restores the db # This also might be necessary when doing a db import with a different password. docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "alter user lemmy with password 'bleh'" @@ -41,7 +42,7 @@ docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "alter user lemmy with pas If you haven't federated yet, you can change your domain name in the DB. **Warning: do not do this after you've federated, or it will break federation.** -Get into `psql` for your docker: +Get into `psql` for your docker: `docker-compose exec postgres psql -U lemmy` @@ -73,5 +74,3 @@ update community set shared_inbox_url = replace (shared_inbox_url, 'old_domain', ## More resources - https://stackoverflow.com/questions/24718706/backup-restore-a-dockerized-postgresql-database - -