Issue
How do I backup my Drupal website's files?
Resolution
It's important to regularly back up the complete file structure of your Drupal website, including the original Drupal distribution, any modules or themes that you may have added, and the uploaded files that Drupal manages.
All of these files are required if you want to restore your website in case of catastrophic failure, set up copies of your website for development, testing or upgrade staging, or move your website from one server to another server.
There are several methods that you can use to back up your Drupal website, including copying files using an SFTP client, using command-line tools and external services.
- SFTP client
- Command line
- Drush
- Incremental external backups
SFTP client
Backing up your website can be as simple as copying all of your website's files back to your local computer for archival. To do this using SFTP:
For ongoing, regular backups, ensure that your SFTP client is configured to transfer only new or updated files, which can save both time and network bandwidth.
- On your computer, create an archive folder for your website's files.
- Open an SFTP connection to the remote server.
- Copy the contents of your website's docroot to the archive folder you created on your computer.
Command line
You can also use a command-line tool to transfer your website's files from a remote server to your local computer for backup. Two of these tools (rsync and scp) and their use are described as follows:
-
rsync
Using
rsync
only transfers remote files that are new or updated since the last backup, saving time and bandwidth.To make a local backup of your website's files from a remote web server, use the following
rsync
command on the command line of your local computer, (not signed in to your remote webserver):rsync -avz -e ssh [username].[environment]@[example.com]:/path/to/[docroot] /local/path/
-
scp
To make a backup of your website's files (located on a remote web server), use the
scp
command on the command line of your local computer, (not signed in to your remote webserver). The followingscp
command copies all of the files on your remote server to your local computer:scp -r [username]@[example.com]:/path/to/[docroot] /local/path
Drush
One way to get a full, compressed archive of a website is to use Drush . The drush archive-dump
command can back up your code, files, and database into a single file. Use this command with caution, because Acquia can not guarantee performance on a production website if this is used.
Note: drush archive-dump has been deprecated in drush 9.
Incremental external backups
A full rsync of files that has been automated via a cron task, while simple to setup is not always the best solution because it will copy the entire filesystem each time. A backup of the entire files directory is not always desirable as things like image derivatives, css and js files are perishable.
Given that only a percentage of the files would change from day-to-day, a full rsync is more inefficient and time intensive than it needs to be. An incremental external backup might be a better solution and have more features than a 1:1 backup.
There are several automated file backup services/tutorials:
- https://github.com/rsnapshot/rsnapshot
- http://www.rsync.net
- http://www.evbackup.com
- https://www.strongspace.com
- http://eberly.org/2008/10/27/how-i-automated-my-backups-to-amazon-s3-using-rsync
Backup and Migrate module
You can add the Backup and Migrate module to your website, which allows you to back up your website's files to both your local computer and to other offsite solutions. You can also use the module to migrate your website between environments.For more information about using the module, see the module's project page on drupal.org.