I'm trying to create a cronjob to back up my database every night before something catastrophic happens. It looks like this command should meet my needs:
0 3 * * * pg_dump dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz
Except after running that, it expects me to type in a password. I can't do that if I run it from cron. How can I pass one in automatically?
c:\Program files\postgresql\9.3\bin> pg_dump -h localhost -p 5432 -U postgres test > D:\backup. sql ... After above command enter User "postgres" password and check D:\ drive for backup.sql file. Follow this answer to receive notifications.
pg_dump can be used to backup an entire database, then pg_restore can be used to examine the archive and/or select which parts of the database are to be restored. The most flexible output file formats are the “custom” format ( -Fc ) and the “directory” format ( -Fd ).
pg_dump doesn't lock the entire database, it does get an explicit lock on all the tables it is going to dump, though.
The pg_dump command extracts a PostgreSQL database into a script file or another archive file. This utility is for backing up databases. The utility makes consistent backups even if the database is being used concurrently. Readers, writers, and other users won't be blocked from using the database while using pg_dump .
Create a .pgpass
file in the home directory of the account that pg_dump
will run as.
The format is:
hostname:port:database:username:password
Then, set the file's mode to 0600
. Otherwise, it will be ignored.
chmod 600 ~/.pgpass
See the Postgresql documentation libpq-pgpass for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With