You are here

Downloading database backups from the command line

An environment's Databases page in the Acquia Cloud interface lists recent database backups for the environment. However, there is a delay between the time when backups are created and when they are added or removed from the Databases page. As a result, the most recently created backups may not yet be listed, while older backups that have been replaced and deleted may be listed, but not in fact be available for download or for restoring the database. You can use SSH and command line tools to confirm which database backups exist, and download backups even if they aren't displayed on the Databases page.

You may also want to use command line tools to download backups if they are very large (over 1 GB), since large downloads over HTTP from the Acquia Cloud interface are more prone to failure.

Required permissions

To run commands on an Acquia Cloud environment, you must have the necessary permission. For non-production environments (dev or stage), you must have the Add SSH key to non-production environments permission. For production environments (prod), you must have the Add SSH key to production environments permission. By default, administrators and users with the Team Lead or Senior Developer roles have these permissions and users with the Developer role do not. For more information, see Working with roles and permissions.

Viewing available backups

To view which backups are actually available on an environment, complete the following steps:

SFTP

If you want to download all of your backups at once, replace yourdatabase-date.sql.gz with an asterisk (*). You can also use SFTP in interactive mode by omitting everything after hosting.acquia.com.

The -i flag tells SFTP to use a specific key. Other useful flags are -b (batch mode) and -v (verbose, used for debugging issues). You can find more information on these options here, as well as information on using SFTP in interactive mode from the command line.

SCP

The -r flag recursively copies the specified directory; if you're using this command to copy files from your docroot, for example, this will copy everything in subdirectories as well. Depending on your version of SCP, this may include symbolic links, so use caution if there are symbolic links to your files directories in the directory tree where you're using -r.

rsync

The -a flag uses archive mode, which is a series of options under one flag that attempt to preserve as exactly as possible the file structures being transferred. This includes copying symlinks as symlinks, copying directories recursively, and preserving the owner:group settings on files and directories. The -v flag provides verbose output, useful in debugging or just keeping track of progress, and -z compresses files during data transfer. The -e "ssh -i ${KEY}" part tells rsync to use SSH to pass key information. There are other options that can be passed in the -e flag that can be useful for synchronizing data, such as --ignore-existing (do not update files that already exist on the receiving end) and --delete (delete files from the destination directory that do not exist in the source directory).

Important

There is a full list of options here, but be careful to practice on non-essential data, especially if using any of the synchronization or delete options.

Restoring backups from the command line

To restore the database in an Acquia Cloud environment from a backup file, complete the following steps:

Ensure that your database backup is unzipped and that it is in .sql format.

Drop your existing database, using a Drush command similar to the following:

drush @[site].[env] ah-db-import --db=[db_name] --drop

where:

[site] is the name of your application on Acquia Cloud.

[env] is the environment into which you're importing your database. Acceptable values are dev (Development), test (Staging), and prod (Production).

[db_name] is the name of your database. Use the database name shown on the Databases page for the environment, not an environment-specific name. For example, if your site name is example, your default database name will probably be example, and you should use that rather than an environment-specific name like exampledev or exampletest.

Run the following Drush command to restore your backup:

drush @[site].[env] ah-db-import /path/to/backup/file

After your database has been restored, Acquia Cloud displays the following message: