Skip to content

Instantly share code, notes, and snippets.

@sikli
Last active October 4, 2020 16:15
Show Gist options
  • Save sikli/fb83a02cc098326286a67ed08230ba04 to your computer and use it in GitHub Desktop.
Save sikli/fb83a02cc098326286a67ed08230ba04 to your computer and use it in GitHub Desktop.
Backup a postgres db without password by creating a .pgpass file
sudo touch ~/.pgpass
echo 'host:5432:somedb:someuser:somepass' >> ~/.pgpass
sudo chmod 600 ~/.pgpass
sudo chown login_username:login_username .pgpass
export PGPASSFILE='/home/user/.pgpass'
pg_dump -U postgres -h localhost db_name -F c | gzip > /mnt/backup/bkp_name.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment