Adding a compressed / gzip version for backup and restore.

This commit is contained in:
Dessalines 2023-01-17 11:03:35 -05:00
parent 1f600af4c2
commit c783b3425f

View file

@ -6,17 +6,18 @@ When using docker or ansible, there should be a `volumes` folder, which contains
### Incremental Database backup ### 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 ```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 ### A Sample backup script
```bash ```bash
#!/bin/sh #!/bin/sh
# DB Backup # 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 # Volumes folder Backup
rsync -avP -zz --rsync-path="sudo rsync" MY_USER@MY_IP:/LEMMY_LOCATION/volumes ~/BACKUP_LOCATION/FOLDERNAME 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 # Drop the existing DB
docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
# Restore from the .sql backup # Restore from the .sql.gz backup
cat db_dump.sql | docker exec -i FOLDERNAME_postgres_1 psql -U lemmy # restores the db 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. # 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'" docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "alter user lemmy with password 'bleh'"
@ -73,5 +74,3 @@ update community set shared_inbox_url = replace (shared_inbox_url, 'old_domain',
## More resources ## More resources
- https://stackoverflow.com/questions/24718706/backup-restore-a-dockerized-postgresql-database - https://stackoverflow.com/questions/24718706/backup-restore-a-dockerized-postgresql-database