Restoring a Backup

There are different Cloud Container Images you can use so the backup restore procedure may be different depending on the image used.

The /container/backups/ directory is the "base path" for the backups and you should find subdirectories for various dates. The subdirectory names indicate at what day/time the backup was taken so let's call these subdirectories snapshots. There's also a symbolic link named latest that points to the latest backup taken.

When browsing a snapshot directory you may notice the file structure is very similar to the Container's file structure.

In this article, we explain the procedures we would suggest you follow if you need to restore your Container files or Database from a backup. It's a good idea to back up your Container before applying significant changes. You can read more about Backing up a Container.

Restoring a MySQL database for a Web Container

Assuming you wish to restore from the latest copy taken, follow the steps below:

  1. Connect to your Container via SSH.
  2. Go to the directory that contains the backup file you wish to restore and list the dump filename.
    cd /container/backups/latest/databases/
    ls
  3. The command below is a template. This should help you uncompress the file and restore it into the database. Replace the uppercase strings as required.
    gunzip < FILENAME.sql.gz | mysql -h MYSQL_HOSTNAME -u USERNAME -p DATABASE
  4. Type in the database username password when prompted.
  5. No data will be returned if all went well. Check the database has been restored as expected.

We would suggest reading the MySQL Databases section in case you are not sure what command parameters to use.

Restoring Web Container's application files

You can use rsync to restore a website snapshot, follow the steps below:

  1. Connect to your Container via SSH.
  2. Go to the directory that contains the backup files you wish to restore. Check the files are as expected.
    cd /container/backups/
    ls
    ls /container/backups/latest/application/
  3. Copy the files to the running Container as required. Just as an example, we are restoring from the latest backup taken.
    rsync --archive --stats --delete /container/backups/latest/application/ /container/application/
  4. Check the files have been restored, test your application as required.

Restoring Web Container's configuration files

You can use the backup files as a reference and restore individual files as needed. It's easy to restore all configuration files though. This is what we are going to do next:

  1. Connect to your Container via SSH.
  2. Go to the directory that contains the backup files you wish to restore. Check the files are as expected.
    cd /container/backups/
    ls
    ls /container/backups/latest/config/
  3. Copy the files to the running Container. Just as an example, we are restoring from the latest backup taken.
    rsync --archive --stats --delete /container/backups/latest/config/ /container/config/
  4. Using the SiteHost Control Panel, reboot the Container to apply the changes.
  5. Test the Container is working as expected.

Restoring PostgreSQL Container database

PostgreSQL Containers backup happen in two different stages. The first stage is a cron job dumping the databases to a /container/application/backup/ directory. The second stage is when these files are copied over to the secure offsite location.

If you wish to restore the latest backup taken, follow the steps:

  1. Connect to your Container via SSH.
  2. Go to the directory that contains the backup files you wish to restore. Check the database dump filename.
    cd /container/backups/latest/application/backup/
    ls
  3. If required, drop the database you wish to restore, recreating it just after.
  4. The command below is a template. This should help you uncompress the file and restore it into the database. Replace the uppercase strings as required.
    gunzip < FILENAME.dump.gz | psql -h PGSQL_HOSTNAME -U USERNAME DATABASE
  5. Type in the database username password when prompted.
  6. Check the database has been restored as expected.

We would suggest reading the Connecting to a Container article if you want to learn more about the parameters used and default passwords.

Restoring MongoDB Container database

MongoDB Container backups happen in two different stages. The first stage is a cron job dumping the databases to a /container/application/backup/ directory. The second stage is when these files are copied over to the secure offsite location.

If you wish to restore the latest backup taken, follow the steps:

  1. Connect to your Container via SSH.
  2. Go to the directory that contains the backup files for the database you wish to restore. Check the database dump directory name.
    cd /container/backups/latest/application/backup/
    ls
  3. If required, remove the database you wish to restore. The commands below are templates. Replace the uppercase strings as required.
    mongo --host MONGO_HOSTNAME
    use DATABASE
    db.dropDatabase()
    exit
  4. Restore the backup files into the database.
    mongorestore --host  MONGO_HOSTNAME --nsInclude DATABASE.* /container/application/backup/
  5. Check the database has been restored as expected.