Backup Postgresql Database from Docker » History » Version 1
Viacheslav Anzhiganov, 02/19/2025 03:45 AM
1 | 1 | Viacheslav Anzhiganov | # Backup Postgresql Database from Docker |
---|---|---|---|
2 | |||
3 | ``` |
||
4 | docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql |
||
5 | ``` |
||
6 | |||
7 | Creates filename like dump_2023-12-25_09_15_26.sql |
||
8 | |||
9 | If you want a smaller file size, use gzip: |
||
10 | |||
11 | ``` |
||
12 | docker exec -t your-db-container pg_dumpall -c -U postgres | gzip > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz |
||
13 | ``` |
||
14 | |||
15 | If you want even smaller file sizes use brotli or bzip2: |
||
16 | |||
17 | ``` |
||
18 | docker exec -t your-db-container pg_dumpall -c -U postgres | brotli --best > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.br |
||
19 | ``` |
||
20 | |||
21 | or |
||
22 | |||
23 | ``` |
||
24 | docker exec -t your-db-container pg_dumpall -c -U postgres | bzip2 --best > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.bz2 |
||
25 | ``` |
||
26 | |||
27 | Restore your databases |
||
28 | |||
29 | ``` |
||
30 | cat your_dump.sql | docker exec -i your-db-container psql -U postgres |
||
31 | ``` |