How to create a backup of an POSTGRES DB using bash?
asked Oct 14, 2009 at 18:34
Elitmiar
37.2k77 gold badges183 silver badges233 bronze badges
3 Answers 3
pg_dump -U some_user_name -f dump.file -Fc database_name
That's all.
If you need to authenticate with password - use pgpass file.
answered Oct 14, 2009 at 19:17
user80168
Sign up to request clarification or add additional context in comments.
Comments
Use pg_dump.
answered Oct 14, 2009 at 18:42
Pablo Santa Cruz
182k33 gold badges250 silver badges300 bronze badges
1 Comment
Elitmiar
I have difficulties including the username and password with pg_dump
Ideally you should add an scheduled job to crontab to be executed daily. The following will create a gzipped sql file with timestamp. SQL dumps otherwise could be very big.
pg_dump database_name | gzip -c > ~/backup/postgres/database_name-`/bin/date +%Y%m%d-%H%M`.sql.gz
answered Feb 29, 2012 at 10:43
Maksym Kozlenko
10.4k2 gold badges69 silver badges55 bronze badges
Comments
default