I deleted customer data in production
Well, you fucked up pretty good. Don’t do it again.
How do I restore it?
Luckily we have backups. There are several ways to restore the data. I present one way of doing it here:
In Google cloud console you can create a clone of the db from the listing of instances. Use the … menu. Select a time before the last backup. This will make a clone of the instance with the exact same config. This will make it easier to connect and such, as everything will work the same way as production.
Take note of the instance name and add an entry to you compose file for your local sql proxy. Now you can connect to the db and fetch the data you deleted using sql queries.
If you deleted an entire schema it might be easier to dump the schema and do a restore.
pg_dump --no-owner --no-acl --verbose --format=custom "dbname=myDb host=localhost port=5497 user=someuser@tritt.no password=abc" --schema=_myschemaID > db.dump
Now you have a file with the schema data. Connect to the production db and do a restore of the schema
PGHOST=localhost PGPORT=5444 PGUSER=someuser@tritt.no pg_restore -d myDb --schema mySchemaId db.dump