mirror of
https://github.com/LemmyNet/lemmy-docs.git
synced 2024-11-22 04:11:09 +00:00
Adding a compressed / gzip version for backup and restore.
This commit is contained in:
parent
1f600af4c2
commit
c783b3425f
1 changed files with 7 additions and 8 deletions
|
@ -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'"
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue