Table of contents

Restore from offsite backups

We use duplicity to perform offsite backups. Some backups are encrypted with GPG before being shipped to an Amazon S3 bucket.

You will find the fingerprint of the key in hieradata/production.yaml within the govuk-puppet repository. The key and passphrase are both stored in encrypted hieradata in the govuk-secrets repository. The same private key is used for all offsite backups).

Restore datastore from offsite backups

Note: Ensure you have followed the Pre-requisites for restoring backups before attempting a backup restore.

Download a backup

  1. Download the latest backup with:

      duplicity restore --file-to-restore data/backups/ s3:// /tmp/latest.tbz2
    • When this completes you may see the following ‘error’:

      Error '[Errno 1] Operation not permitted: '/tmp/latest.tbz2'' processing .

      This doesn’t seem to have any significant consequences and can be ignored.

Restore a backup

  1. Extract the downloaded backup

      cd /tmp
      tar xvjf latest.tbz2
  2. Extract the dump that you want to restore:

      bunzip2 latest/foo.sql.bz2
  3. Restore with:

      sudo mysql < foo.sql

This will restore the contents of file foo.sql to the database name that the dump was taken from, creating it if it doesn’t exist.

Restore assets from offsite backups

This shows the example process of restoring files for Whitehall attachments.

Note: Ensure that you can connect to the S3 bucket using the supplied access keys. To do this, follow the Pre-requisites for restoring backups section.

  1. SSH to the machine where you want to restore the backup, for example asset-master-1.backend.
  2. ls the destination bucket

      export AWS_ACCESS_KEY_ID=<access_key_id>
      export AWS_SECRET_ACCESS_KEY=<secret_access_key>
      aws s3cmd ls s3://govuk-offsite-backups-production/assets-whitehall/
    • If you can view objects inside the bucket you should have access.
    • The buckets are as described in hieradata/production.yaml in the govuk-puppet repo.
  3. Now you’ll be able to see the status of duplicity:

      asset-master-1:~$ duplicity collection-status s3://
  4. Import the GPG secret key from the credentials store as per the section to Set up GPG keys to decrypt backups

  5. Once the key is imported, you can list files:

      asset-master-1:~$ duplicity list-current-files s3://
  6. In order to restore the files, you may need to change the owner of the /mnt/uploads/whitehall directory to your user temporarily, and remove any files that already exist in that directory.

  7. Run a restore:

      asset-master-1:~$ duplicity restore --file-to-restore mnt/uploads/whitehall/ s3:// /mnt/uploads/whitehall

Clean up

Once the backup has restored correctly, make sure you revert all the manual actions you’ve taken. These may include:

  1. Changing the owner of the assets files
  2. Removing the secret key from the GPG keyring (gpg --delete-secret-key 12345678)

Pre-requisites for restoring backups

On the machine where you want to restore the backup:

VM requirements

For the backup and restore drill, you will restore and unpack a MySQL database on a Vagrant VM.

On a fresh VM, you may require the following packages for this exercise:

Packages via apt-get

sudo apt-get install duplicity python-pip python-boto mysql-server

Python libs via pip

sudo pip install s3cmd

Set up GPG keys to decrypt backups

You will need access to production hieradata credentials to retrieve the AWS credentials and GPG key to decrypt the backups.

  1. Retrieve the keys and credentials from the Deployment repo following these instructions

    • You are looking for:
  2. Ensure that you can connect to the S3 bucket:

      export AWS_ACCESS_KEY_ID=<access_key_id>
      export AWS_SECRET_ACCESS_KEY=<secret_access_key>
      s3cmd ls s3://
    • If you receive a 403 error, try:

      s3cmd ls s3://govuk-offsite-backups-production/govuk-datastores/

      If you can view objects inside the bucket you now have access.

  3. Now you can see the status of duplicity:

      duplicity collection-status s3://

Import key on machine

On the machine where you’ll be running the restore:

  1. Create a file containing the backup::assets::backup_private_gpg_key GPG key

  2. Import it with:

      gpg --allow-secret-key-import --import <path to GPG key file>
    • Confirm the key has been imported correctly with:

      gpg --list-secret-keys
  3. Once the key is imported, you’ll be able to list files:

      duplicity list-current-files s3://

Rotating offsite backups GPG keys

Please see

This page is owned by #2ndline and needs to be reviewed