On this page
- What to back up
- Prefer your hosting provider's backup tools
- Examples: Create backups using common tools
- Create a backup with Backup & Migrate module
- To create a backup
- To restore a backup
- Create a backup using Drush
- Create a snapshot
- Restore a snapshot
- Create a backup using generic command-line tools
- Step 1: Database backup
- Step 2: Files backup
- Step 3: Code backup
- Using DDEV
- Create a snapshot:
- Restore a snapshot:
- Other considerations
- Test your backups
- Schedule your backups
- Backup retention strategy
- Secure backup storage
- Restoring from backups
- Wrap-up
How to back up your Drupal site
Whether making a backup before you apply updates to Drupal core and contributed modules, or keeping regular snapshots to help with recovery from other system failures, you need to make sure you're backing up the right things.
In this tutorial, you’ll:
- Learn what to include in your Drupal backup.
- Walk through examples of how to create (and restore) a backup using common tools.
- Understand how to get started making a backup of your site.
By the end of this tutorial, you'll know what is required to create a complete backup of a Drupal site, and have some guidance on how to get started with your specific environment.
What to back up
A complete backup should allow you to easily roll your site back to its previous state and should include:
- Database snapshot: Your database contains all your content, and user information. Your backup should include a complete dump of this database.
- User-uploaded files: This includes images, documents, and any other user uploaded files that are part of your site's content. Your backup should contain a copy of these files, commonly located in the sites/default/files directory.
- Current codebase snapshot: Depends on your deployment workflow. (Essential for non-Git-managed sites; optional if using Git). Your backup should include the ability to return your codebase to a known working state. That might mean a Git tag, or a .zip file with the code as it was before you started making changes.
- Tested and documented rollback procedure: Ensure you can confidently revert if something goes wrong.
Prefer your hosting provider's backup tools
If your hosting provider offers backup tools or automated snapshot features, use them! These tools are often optimized for your server environment and can save you time and effort. Many managed Drupal hosting services provide one-click backups, scheduled backups, and easy restoration tools. Review your hosting provider's documentation before setting up custom backups.
Examples: Create backups using common tools
Below are some examples of how to create backups using tools that are commonly available in Drupal environments. Use these examples to guide you towards making backups in your specific environment.
Create a backup with Backup & Migrate module
The Backup & Migrate module offers a way to backup and restore your Drupal site's database and files from within the Drupal administration user interface.
Use this module if you don't have command-line access to your hosting environment.
To create a backup
- Download and install the module using Composer, or Project Browser (for Drupal CMS).
- Navigate to Configuration > Development > Backup & Migrate (/admin/config/development/backup_migrate).
- Choose the components you want to back up (e.g., database, files).
- Select a destination (e.g., download or server directory).
- Click Backup now.
⚠️ Note: You need to repeat this process to backup both the files and database separately!
To restore a backup
- Go to the Restore tab.
- Upload or select the backup file.
- Choose a destination.
- Click Restore now to revert to that backup.
Create a backup using Drush
Drush (which is commonly available on Drupal hosting environments) can create a complete backup (database, files, and code) in a single archive:
Create a snapshot
drush archive:dump --destination=testing-updates.tar.gzRunning this command generates the file, testing-updates.tar.gz, which contains a backup of your site's database, files, and code.
Restore a snapshot
drush archive:restore testing-updates.tar.gzLearn more about Drush backups.
Create a backup using generic command-line tools
Step 1: Database backup
Use mysqldump (or pg_dump for Postgres) to create a snapshot of the database.
mysqldump -u <db_user> -p --single-transaction --quick --lock-tables=false <db_name> > drupal-db-backup-$(date +%Y%m%d).sqlReplace <db_user> and <db_name> with your credentials. You'll be prompted for a password.
Tip: Use drush sql:dump instead which can read the necessary DB settings from the site's configuration.
Step 2: Files backup
tar czvf drupal-files-$(date +%Y%m%d).tar.gz sites/default/filesReplace sites/default/files with the path to your user-uploaded files directory. Don't forget your private files directory, which might be separate and located elsewhere. If you don’t know where to find these, the following command can help you locate them:
drush core-status --fields=files,privateStep 3: Code backup
If you're using Git, your codebase is versioned, but be sure to back up user files and database content separately.
If you're not using Git you should create a snapshot of the entire codebase of your site:
tar czvf drupal-code-$(date +%Y%m%d).tar.gz .Using DDEV
For local development environments, DDEV provides convenient backup commands, that you can use while testing updates or new features:
Create a snapshot:
ddev snapshot --name=testing-updatesCreates a database snapshot and file backup in .ddev/.
Restore a snapshot:
ddev snapshot restore --name=testing-updatesLearn more about DDEV backups.
Other considerations
Test your backups
Regularly test your backups by restoring them in a development environment. This ensures your backups are valid and you can confidently perform restorations when needed.
Schedule your backups
Once you've figured out a strategy for creating backups, it's a good idea to automate that process. Set a backup schedule according to your site's activity and needs. Regular backups minimize data loss and facilitate quicker recovery.
For command-line-based approaches, consider creating a script in your project, for example, ./scripts/backup.sh, that contains the necessary commands to create a backup and then use cron (or another task runner) to regularly run that script.
Backup retention strategy
Maintain multiple backups to safeguard against data loss. Example:
- Daily backups: Retain for the past 7 days.
- Weekly backups: Retain for the past 4 weeks.
- Monthly backups: Retain for the past 6 months.
Adjust based on your site's update frequency and storage availability.
Secure backup storage
Store backups in secure offsite locations to protect against server failures or breaches:
- Cloud storage services (Dropbox, Google Drive, Amazon S3).
- Remote servers with restricted access.
Ensure backup files are not publicly accessible; remember they contain sensitive user and business data.
Restoring from backups
Restoring from backups involves:
- Revert any code changes: Revert any changes to the code that may have happened since the backup was created. The state of the code needs to match that of the DB snapshot.
- Database restoration: Import your `.sql` backup. It's a good idea to drop any existing tables first before importing the backup to ensure there are no conflicts.
- File restoration: Upload backed-up files to their appropriate directories on your server.
Wrap-up
Always back up before applying site updates. This tutorial explained what to include in your backup and demonstrated various tools to help ensure a smooth update process and reliable recovery if needed.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.