Restoring
One reason that you might want to restore a database from a SQL-dump is to update the DEV database with the contents of the PROD database. These instructions describe how to restore the DEV and QA databases with the latest daily backup from PROD.
Because all EAS developers log into the various EAS Linux servers using the same login credentials, the information below could be (re-)derived at any time by examining the complete shared history by running the history
command from an SSH session, for example, while logged in to the EAS DEV database server ((virtual) machine).
Name and Location of Daily Database Backups
Each EAS database in each of the environments is backed up every night, so there is always a SQL-dump file available for database restoration.
- Path to daily database backups:
/mnt/backup/pg/daily
- File format for daily backups:
easproddb.sfgov.org-eas_prod-YYYYMMDD.dmp
easproddb.sfgov.org-sfmaps_prod-YYYYMMDD.dmp
- Example backup files:
easproddb.sfgov.org-eas_prod-20170613.dmp
easproddb.sfgov.org-sfmaps_prod-20170613.dmp
Name and Location of Database Restoration Scripts
Each EAS environment has a shell script named 'restore_dbs.sh
' that is located in the dev user's home directory.
When the script is run with the correct arguments it performs the entire EAS database restoration process for the given server.
Step-by-Step EAS Database Restoration Guide
- Find a new or updated EAS address that is in the PROD database but not the DEV or QA databases. Hint: To find a new address see the daily automated email containing a list of recent address changes.
- Copy the SQL-dump files from the daily PROD backups to DEV or QA server.
- FTP the daily backup from PROD to a local computer (e.g. your desktop computer).
- See the 'FTP Using FileZilla' section below for one method of transferring files.
- FTP the SQL-dump backup files from your local computer to the DEV or QA server.
- For consistency with the steps below upload the files to '
/var/tmp/'
on the DEV or QA server.
- Log in to the target EAS database server using SSH.
- See also PuTTY and SSH Instructions
Copy the database restore shell script from your home directory to the target directory. This is only necessary the very first time that you do this.
cp restore_dbs.sh /var/tmp
Move to the target directory.
cd /var/tmp
Change the ownership of the database restore shell script. This is only necessary the very first time that you do this.
sudo chown postgres:postgres restore_dbs.sh
If the database restore shell script is not executable, then modify this permission for the file owner.
sudo chmod u+x restore_dbs.sh
Change the ownership of the SQL-dump file(s). The following examples use the SQL-dump files from 2a above.
sudo chown postgres:postgres easproddb.sfgov.org-eas_prod-20170613.dmp sudo chown postgres:postgres easproddb.sfgov.org-sfmaps_prod-20170613.dmp
Become the user
postgres
.sudo -u postgres -i
While logged in as the user
postgres
, move into the target directory.cd /var/tmp
Restore the database(s). This normally just takes a couple of minutes to finish. If the one-argument example below does not work, then use the two-argument example.
./restore_dbs.sh DEV easproddb.sfgov.org-eas_prod-20170613.dmp ./restore_dbs.sh DEV easproddb.sfgov.org-sfmaps_prod-20170613.dmp OR ./restore_dbs.sh DEV easproddb.sfgov.org-eas_prod-20170613.dmp easproddb.sfgov.org-sfmaps_prod-20170613.dmp OR ./restore_dbs.sh QA easproddb.sfgov.org-eas_prod-20170613.dmp easproddb.sfgov.org-sfmaps_prod-20170613.dmp
The restoration order of the two dmp files matters. The *eas_prod* dump must be restored before the *sfmaps_prod* dump. Otherwise a 'Data Retrieval Error' will occur.
- Exit out of both shells to close the SSH session to the target EAS database server.
- You should confirm that your database(s) have been restored by following these steps:
- Check Database
- Establish your SSH tunnel to the target EAS database server.
- Invoke pgAdmin.
- Navigate to a restored database and verify that its contents are what you expect.
- Check Web App
- Check Database
FTP Using FileZilla
Download and install FileZilla from https://filezilla-project.org/
- See the network folder W:\Software\FileZilla for previously downloaded versions.
- Open FileZilla, navigate to 'Site Manager', and set up connections.