![]() Pg_dump -U dbuser -w mydatabase >/var/custom/backups/pg_ ![]() Set the environment variable PGPASSFILE before executing pg_dump.Įxample: PGPASSFILE=/opt/custom/backup/.pgpass The location of the password file can be provided in one of the following two ways: PGPASSFILE environment variable This is especially useful if you need to run pg_dump under a user that does not have a home directory, or if you want to keep all passwords in a specific location. pgpass with a different host account in order to secure those credential, might be pointless.Īnother option to pass the database password is using the PGPASSFILE environment variable or the passfile URI parameter.īoth expect a password file in the format hostname:port:database:username:passwordįor example localhost:5432:mydatabase:dbuser:userspasswordĪs described in other answers for ~/.pgpass, but you are not confined to this specific path and and file name. pgpass afterward because in some environments, the default SSH user can sudo without a password, for example an EC2 instance with the ubuntu user, so using. Just substitute the first couple of config lines with whatever you need - obviously.įor those not interested in the S3 backup part, take it out - obviously. # "latest" is always good to have because it makes it easier for dev-ops to useĪws s3 cp. # s3 is cheap, so don't worry about a little temporary duplication here # EC2 instances can use instance permissions to push files to S3Īws s3 cp. ![]() # Backing up to AWS obviously requires having your credentials to be set locally Gpg -batch -passphrase "$PASSWORD" -cipher-algo AES256 -compression-algo BZIP2 -co "$.gpg". Ssh "$SSH_HOST" "pg_dump -U $DB_USER -h $DB_HOST -C -column-inserts $DATABASE" | gzip >. pgpass credentials and push to S3: #!/usr/bin/env bashĮcho " = The DB password, which is also used for GPG encryption of the backup file"Įcho " my-backup-script.sh my_db my_password"Įcho "$DB_HOST:5432:$DATABASE:$DB_USER:$PASSWORD" | ssh "$SSH_HOST" "cat > ~/.pgpass chmod 0600 ~/.pgpass"Įcho "backup over SSH and gzip the backup. Backup over ssh with password using temporary.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |