---
title: "Downloading database backups from the command line"
date: "2024-02-14T06:18:38+00:00"
summary: "Learn how to efficiently download database backups from the command line using SSH and popular tools like SFTP, SCP, and rsync. Ideal for developers managing large backups on Acquia Cloud Platform."
image:
type: "page"
url: "/acquia-cloud-platform/downloading-database-backups-command-line"
id: "1c976354-dc71-4298-8dee-07d403269db2"
---

Table of contents will be added

Note

The instructions in this section do not apply to environments running on [Cloud Next](/acquia-cloud-platform#cloud-next-benefits) technologies. Use [Acquia CLI](../../../acquia-cli.html), the Cloud Platform user interface, or Cloud Platform API v2 to download database backups on Cloud Next environments.

An environment’s **Databases** page in the Cloud Platform interface lists recent database backups for the environment. You can also use SSH and command line tools to confirm which database backups exist and download them directly from your environment, if desired.

Acquia recommends using command line tools to download backups if they are large (over 1 GB), since large downloads over HTTPS from the Cloud Platform interface may not complete successfully.

Required permissions
--------------------

To run commands on a Cloud Platform 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](/acquia-cloud-platform/access/teams/roles).

Viewing available backups
-------------------------

To view which backups are actually available on an environment:

1.  [Connect to your infrastructure using SSH.](/acquia-cloud-platform/manage-apps/command-line) For example, you can use a command similar to the following:
    
        ssh clouddocs.dev@ded-1234.prod.hosting.acquia.com
    
2.  Change directory to the `/backups` directory for the environment.
    
    *   Development environment: `/mnt/files/[sitename].dev/backups`
    *   Staging environment: `/mnt/files/[sitename].test/backups`
    *   Production environment: `/mnt/files/[sitename].prod/backups`
    
    If you want to view backups for the Development environment, use a command similar to the following:
    
        cd /mnt/files/clouddocs.dev/backups
    
3.  Run the `ls` command to determine which backup files are present.

You can download the backup files you want using command line tools.

Downloading backups with command line tools
-------------------------------------------

The following is a set of examples for downloading database backups with several command-line tools. Be sure to either replace or set the following variables in the examples:

*   `sitename`: Your application’s [sitename](/definitions/sitename).
*   `env` - The Cloud Platform environment. For most applications, one of `prod` (Production), `test` (Staging), or `dev` (Development).
*   `server`: Your server name, which you can find on the **Infrastructure** page. For example, `ded-123`.

You can use any GUI tool that supports these protocols, such as Fetch or WinSCP.

### SFTP

To download with SFTP, use a command like the following:

    sftp [sitename].env]@[server].prod.hosting.acquia.com:/mnt/files/[sitename]/backups/yourdatabase-date.sql.gz /path/to/your/backup/folder

To download all your backups at once, replace `yourdatabase-date.sql.gz` with an asterisk (\*). You can also use SFTP in the 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).

### SCP

To download with SCP, use a command similar to the following:

    scp -r  [sitename].[env]@[server].prod.hosting.acquia.com:/mnt/files/[sitename]/backups/ /path/to/your/backup/folder

The `-r` flag recursively copies the specified directory if you’re using this command to copy files from your docroot. For example, this command 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

To download with `rsync`, use a command like the following:

    rsync -avz -e "ssh -i ${KEY}" [sitename].[env]@[server].prod.hosting.acquia.com:/mnt/files/sitename/backups/ /path/to/your/backup/folder

The `-a` flag uses archive mode, which is a series of options under one flag that attempt to preserve 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

A [full list of options](http://ss64.com/bash/rsync_options.html) is available, 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 a Cloud Platform environment from a backup file:

1.  Ensure that your database backup is unzipped and that it is in `.sql` format.
2.  Drop your existing database, using the [drush sql-drop](https://www.drush.org/13.x/commands/sql_drop/) command:
    
        drush @[site].[env] sql-drop [--uri=my.site.com]
    
    where:
    
    *   `[site]` is the name of your application on Cloud Platform.
    *   `[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`.
3.  Run the following [ah-db-import](/acquia-cloud-platform/manage-apps/command-line/drush/custom-commands#ah-db-import) Drush command to restore your backup:
    
        drush @[site].[env] ah-db-import /path/to/backup/file
    

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

    Imported into database successfully

For information about database backup locations, see [Downloading backups from the command line](../back-up.html#cli-download).