Skip to content

Instantly share code, notes, and snippets.

@mkorkmaz
Created October 9, 2018 20:48
Show Gist options
  • Save mkorkmaz/b4784625683b53bef1ac8598b82cb971 to your computer and use it in GitHub Desktop.
Save mkorkmaz/b4784625683b53bef1ac8598b82cb971 to your computer and use it in GitHub Desktop.
Gets postgresql dump file from the server, restores local database and executes a sql file (i.e a script to reset user passwords for testing purposes)
#
# cron job runs at my-db-server with this configuration
# @daily pg_dump -Fc myRemoteDatabase > /var/lib/postgresql/backups/my-remote-database.dump
#
scp user@ssh.my-db-server.com:/var/lib/postgresql/backups/my-remote-database.dump ./temp.dump
pg_restore -h 127.0.0.1 -p 5432 -U postgres -c -d myLocalDatabase < ./temp.dump
psql -h 127.0.0.1 -p 5432 -U postgres -d myLocalDatabase -a -f ./reset-passwords.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment