Dump/Restore postgres database
Using pg_dump/pg_restore
pg_dump
filepath = "/var/www/#{DateTime.now.to_date.to_s}.dump" config = ActiveRecord::Base.connection_db_config.configuration_hash host, db, username = config[:host], config[:database], config[:username] cmd = "PGPASSWORD='#{ ENV['DATABASE_PASSWORD'] }' pg_dump -F c -v -h #{host} -d #{db} -U #{username} -f #{filepath}" exec cmd
Copy dump file
Using SCP to upload/download dump file: http://rubysnippets.net/documents/download-file-from-remote-server-using-scp
pg_restore
pg_restore --verbose --clean --no-acl --no-owner -d rubysnippets_development /path/to/file.dump
Dump from AWS RDS
Updating... # pg_dump -F c -v -h fast-drop-database.crf6tfouv0h0.us-east-1.rds.amazonaws.com -d fast_drop_staging -U postgres > staging_latest.dump