From e89b2e64bfe9b4eff7d37300449c5f5302953f81 Mon Sep 17 00:00:00 2001 From: JessicaVDussault Date: Thu, 14 Dec 2023 13:43:50 -0600 Subject: [PATCH] adds documentation for importing data into docker also clarifies a few steps of the export process --- docs/backup-and-restore-database.md | 48 ++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/docs/backup-and-restore-database.md b/docs/backup-and-restore-database.md index ceff1838..566f33df 100644 --- a/docs/backup-and-restore-database.md +++ b/docs/backup-and-restore-database.md @@ -13,14 +13,22 @@ a plugin, run this command: cf uninstall-plugin ``` -Then follow the installation instructions found in the plugin's documentation. +Then follow the installation instructions found in the plugin's documentation. Once installed, you may log in and select your org and space: -## Step 1: Exporting data +```bash +cf login -a api.fr.cloud.gov --sso +``` + +## Exporting data from cloud.gov ```bash -# Target the environment you're exporting from +# If you have not already targeted the environment for export or wish to change cf target [-o ] -s +# List the available apps services for this space. Make note of the tock app name and the database service name +cf apps +cf services + # Check to see if a SERVICE_CONNECT service key already exists cf service-keys @@ -31,7 +39,7 @@ cf delete-service-key SERVICE_CONNECT # note the credentials and connection info given in the output cf connect-to-service -no-client -# Back in the original window, dump the database +# Back in the original window, dump the database. This may take several minutes. pg_dump -F c --no-acl --no-owner -f postgres://:@:/ # In the window with the SSH Tunnel, close the SSH tunnel @@ -43,7 +51,7 @@ cf delete-service-key SERVICE_CONNECT Tock retains daily backups for 14 days; for details, see the [cloud.gov backup documentation](https://cloud.gov/docs/services/relational-database/#backups). (Please note that if you are planning contingency tests, the cloud.gov support team prefers at least 48 hours of advance notice.) -## Step 2: Importing data +## Importing data into cloud.gov ```bash # Target the environment you're restoring into @@ -88,3 +96,33 @@ cf delete-service-key SERVICE_CONNECT # Restage the app associated with the service cf restage ``` + +## Importing data into docker locally + +These instructions assume that you already have Docker installed and are set up for [local development](local-development.md). + +```bash +# Make sure the Tock app is running locally +docker-compose up +``` + +From the Docker dashboard application, find the tock database container and open up the terminal. + +```bash +# Connect to the database +psql -U tock_user -d tock + +# from inside the psql terminal, drop the public schema to get rid of testing data +DROP SCHEMA public CASCADE; + +# recreate the public schema +CREATE SCHEMA public; +``` + +From a regular (non-Docker) terminal window, import the database. This may take several minutes. + +```bash +docker exec -i tock-db-1 pg_restore -U tock_user -v -d tock < +``` + +Once the import is done, log in with admin.user@gsa.gov or any user's email which appears in the newly imported data.