Information for: DEVELOPERS   PARTNERS

Copying files to a different environment

Occasionally, you must move files from one Cloud Platform environment to another; for example, from your Development environment to the Staging environment, or from Production to Staging. The Cloud Platform interface allows you to copy files from one environment to another, either all at once, or individually. To copy all files at once, you can use the Cloud API equivalent, or refer to Copying files between environments. If you need to copy only a single file, a single multisite set of files, or a database backup, you can use one of the following methods:

Transferring using your local environment

One option is to download the file to your local machine from one environment and then upload the file to the destination environment.

Only one ssh connection is used at any point, so this method may be the simplest to complete. Using your local environment for file transfer can add time, overhead, and increased network traffic to the process.

Transferring using SCP

You can use scp (Secure Copy) from a command prompt to transfer files using the SSH protocol. Newer versions of scp have an option (-3) to transfer files between two remote infrastructure. This still uses your network connection to tunnel the transfer (so you will still have the latency), but is helpful because it will transfer the file using only one command. If you need to transfer a single small file, this might be the best solution. The command usage will be similar to the following:

scp -3 [email protected]:prod/backups/prod-backup.sql.gz [email protected]:test/import/

On Acquia Cloud Next, the syntax would look like this instead:

scp -3 [email protected]:/shared/private-files/example.txt [email protected]:/shared/private-files/

Using agent forwarding and rsync

As an alternative, you can use SSH with agent forwarding to directly copy files from one environment to another. With agent forwarding, the commands that you run on one infrastructure will use the same credentials to access the other, and you do not need to put a private key in either environment.

The following example assumes that you want to copy a database backup from your Production environment to your Staging environment:

  1. Connect to your Staging environment by using SSH with the -A parameter to allow agent forwarding:

  2. Use rsync to copy the database backup from Production to Staging:

    rsync [source server]:[backup path] [destination path]

    For example:

    rsync --progress [email protected]:prod/backups/prod-backup.sql.gz test/import/

    This copies the file prod/backups/prod-backup.sql.gz on the infrastructure for the Production environment to the test/import directory of the current (Staging) infrastructure.

To copy a single multisite’s set of files, use the rsync command with the --recursive parameter in a command similar to the following:

rsync --progress --recursive [email protected]:prod/sites/othersite/files test/sites/othersite/files

You can complete this all in one step by passing the entire rsync command as the arguments to the SSH command:

ssh -A [email protected] "rsync --progress
[email protected]:prod/sites/othersite/files