RecoveringDeletedData - PresConsUIUC/PSAP GitHub Wiki

When content is deleted from the database, the only way to restore it is from a nightly database backup. But whole backups can't be restored, because that would wipe out all changes made by other users since the backup.

To deal with this situation, the PSAP application has functionality to bulk-export and bulk-import a single institution's data. Backup data is loaded into a one-off application instance, from which the institution data is exported, and and then imported into the production instance. All data associated with an institution is included, except users.

How to do it

  1. Start up a new PSAP development environment with application and PostgreSQL database.

  2. Locate the backup file. (For psap.library.illinois.edu, see here)

  3. Copy the file into the development environment and load it into PostgreSQL, e.g.:

$ createdb psap_backup -T template0
$ psql -f backup.sql psap_backup
  1. Edit the PSAP application's database.yml to use the recovered database.

  2. Find the institution's ID. This will appear in URLs as: /institutions/:id

  3. Use that ID to export all of the institution's data: bundle exec rake psap:export_institution[:id] > recovered.json

  4. Copy this file onto the production server.

  5. Load it into the application: bundle exec rake psap:import_institution[/path/to/recovered.json]