Skip to main content

How to refresh your database on PaaS

This guide is for all GovCMS PaaS users who have a database on their local environment, and want to use it on their GovCMS environment.

For SaaS sites, they would have to raise a Forklift request, and get Service Desk to do this for them.

However, for PaaS users, they have the ability to do it themselves.

It consists of three steps:

  1. Rsync the database to the server
  2. Lagoon SSH into the server
  3. Import the database

What you will need before you can do this:

  • All the correct access to the project
  • Lagoon CLI tool installed and setup
  • A local database you want to import

Step 1

The command is:

rsync -avzP -e "ssh -p 30831 -i ~/.ssh/id_rsa" db.sql PROJECT_NAME-DESTINATION_ENVIRONMENT@ssh-lagoon.govcms.amazee.io:/app/web/sites/default/files/private/

To understand each element:

  • rsync : This is the name of the command to upload the file
  • -avzP : These are the options added to the command
    • a : Archive mode
    • v : Verbose mode
    • z : Compression mode
    • P : Partial and Progress options
  • -e “” : What command are we going to run to connect
  • ssh -p 30831 : SSH connecting on port 30831
  • -i ~/.ssh/id_rsa : Location of your SSH key
  • db.sql : The database you want to transfer up
  • PROJECT_NAME-DESTINATION_ENVIRONMENT : Fairly obvious, Lagoon Dashboard even has a handy “Copy” button that you can use to get this
  • @ssh-lagoon.govcms.amazee.io : The remote server to connect to
  • /app/web/sites/default/files/private : The directory to place the database in

Step 2

Next up, we need to remote into the GovCMS server.  The command is:

lagoon ssh -p PROJECT_NAME -e DESTINATION_ENVIRONMENT

To understand each element:

  • lagoon : The CLI tool we are using
  • ssh : The command to run
  • -p PROJECT_NAME : The project to remote into
  • -e DESTINATION_ENVIRONMENT : Which environment to remote into

Note: Sometimes I personally need to include the -i option and reference my SSH key

Step 3

Finally, now that we are remoted into the server, we just need to import the database.

The command is:

drush sql-drop -y && nohup drush sqlc < web/sites/default/files/private/db.sql

And to understand each element:

  • drush sql-drop -y : Drops the database without asking for confirmation
  • && : Run another command after the first one finishes
  • nohup : Short for “No Hang Up” this prevents your connection from timing out while the database import is happening, which for large databases, can take a while
  • drush sqlc : The Drush SQL-CLI command
  • < web/sites/default/files/private/db.sql : The location of the database file that we rsynced up earlier

Finished

All done, your database has now been imported.