rsyncing files on Acquia Cloud

Rsync

To copy a large number of files from one place to another, one of the better options is to use rsync, which provides either an interactive or non-interactive way to copy files from one location to another, or from one server to another.

To be able to rsync files on Acquia Cloud, you'll need to do the following:

 

  1. Ensure that the user, group, and mode of a file/folder in your files directories are set to permit the web server to have read-only access and to explicitly block any other user from reading your content. This prevents file locks or changes while you're copying data.
  2. Create a new SSH key or use an existing SSH key, and then add the public key to your Acquia account on your account page. See Enabling SSH access.
  3. Place the private key somewhere on the production server. For this example, suppose that you placed the key in the /mnt/files/[site]/files-private/private_key directory, where [site] is the site's name on Acquia Cloud.
  4. To allow access to the key, give it the proper permissions. To do this, use a command similar to the following:
    chmod 600 /mnt/files/[site]/files-private/private_key
  5. Run rsync from either of the production servers (prod_server). For this example, here is some syntax that you can use:
    rsync -rltDvPh -e "ssh -i {path to private key}" {source} {destination}

    If you are using Drush and aliases to download files, you can use a command like this:

    drush rsync @mysite.dev:%files sites/default
  6. Transfer the files folder from staging to production:
    rsync -rltDvPh -e "ssh -i /mnt/files/[site]/files-private/private_key" [user].[env]@[stage_server]:/mnt/files/[stage_name]/sites/default/files/ /mnt/files/[site]/sites/default/files

    In this example, [stage_name] is the name of the staging site's name on Acquia Cloud, and the [stage_server] is the name of the staging server on Acquia Cloud.

These rsync flags ensure that all the files are copied recursively, preserve modification times and symlinks, and so on. For more information on the rsync options used here, see the rsync man page.

Here are a few more examples:

To transfer the files folder from production to staging, execute a command similar to the following:

rsync -rltDvPh -e "ssh -i /mnt/files/[site]/files-private/private_key" /mnt/files/[site]/sites/default/files/ [user].[env]@[stage_server]:/mnt/files/[stage_name]/sites/default/files/

To completely remove and replace:

rsync -rltDvPh /mnt/files/[site]/sites/default/files/ /mnt/files/[site]/sites/default/files --delete

You can also use scp over rsync from a local machine to transfer between two servers. You may need to set up SSH keys between the two servers:

scp -r -P22 [user].[env]@[svr].hosting.acquia.com:/mnt/files/[site]/sites/default/files/ [user].[env]@[svr].hosting.acquia.com:/mnt/files/[site]/sites/default/files

In this example, [user] is your username, and [svr] is the name of the particular server you're moving data to or from.

Contact supportStill need assistance? Contact Acquia Support