How do I backup my Drupal website's files?
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 installing the Backup and Migrate module, copying files using an FTP client, or using command-line tools.
- Backup and Migrate module
- FTP client
- Command line
- Incremental external backups
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.
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 FTP:
For ongoing, regular backups, ensure that your FTP 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 FTP connection to the remote server.
- Copy the contents of your website's docroot to the archive folder you created on your computer.
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:
rsynconly 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
rsynccommand 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/
To make a backup of your website's files (located on a remote web server), use the
scpcommand on the command line of your local computer, (not signed in to your remote webserver). The following
scpcommand copies all of the files on your remote server to your local computer:
scp -r [username]@[example.com]:/path/to/[docroot] /local/path
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: