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
|
### 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'"
|
||||||
|
@ -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.**
|
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`
|
`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
|
## More resources
|
||||||
|
|
||||||
- https://stackoverflow.com/questions/24718706/backup-restore-a-dockerized-postgresql-database
|
- https://stackoverflow.com/questions/24718706/backup-restore-a-dockerized-postgresql-database
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue