Skip to content

Drupal - Site Backup

Regularly backing up your Drupal site is crucial for disaster recovery, before major updates, or when migrating your site. A complete backup consists of two main parts: the database and the files.

The database stores your site’s content, configuration (in Drupal 8+ much configuration is also exportable to files), user information, and more.

Section titled “Method A: Using Drush (Recommended for Developers/CLI Users)”

Drush is a command-line shell and Unix scripting interface for Drupal. If you have Drush installed (typically via Composer: composer require drush/drush):

  1. Open your terminal or command prompt.

  2. Navigate to your Drupal site’s root directory (where your main index.php and composer.json files are located).

  3. Run the command: drush sql:dump --result-file=backup.sql (or vendor/bin/drush sql:dump --result-file=my_database_backup.sql).

This will create an SQL dump file (e.g., my_database_backup.sql) in your Drupal root directory. You can specify a different path for the output file.

Method B: Using phpMyAdmin (Common on Shared Hosting)

Section titled “Method B: Using phpMyAdmin (Common on Shared Hosting)”
  1. Log in to your hosting control panel (e.g., cPanel) and open phpMyAdmin.

  2. Select your Drupal database from the list on the left sidebar.

  3. Click the ‘Export’ tab.

  4. For ‘Export method’, ‘Quick’ is usually sufficient. Ensure the ‘Format’ is set to ‘SQL’.

  5. Click ‘Go’ (or ‘Export’). The database dump file (.sql) will be downloaded to your computer.

Many hosting providers offer built-in backup tools or services. Check your hosting provider’s documentation for specific instructions.

This includes your Drupal codebase (core, modules, themes) and user-uploaded files (images, documents).

Method A: Backing Up the Entire Drupal Root Directory

Section titled “Method A: Backing Up the Entire Drupal Root Directory”

This is the most comprehensive file backup. You need to copy your entire Drupal project directory.

  1. Via SFTP/FTP Client (e.g., FileZilla, Cyberduck, WinSCP): Connect to your server. Navigate to your Drupal root directory (e.g., public_html, htdocs, www). Download the entire directory to your local computer.

  2. Via SSH/Command Line: If you have SSH access, you can create a compressed archive:

    cd /path/to/drupal_root_parent_directory

    tar -czvf drupal_files_backup.tar.gz your_drupal_directory_name/

    Then download drupal_files_backup.tar.gz.

  • The entire Drupal root directory is safest.
  • At a minimum, ensure you back up:
    • sites/default/files (or your active site’s files directory, e.g., sites/yourdomain.com/files): Contains user-uploaded files.
    • themes/: Your custom and contributed themes.
    • modules/: Your custom and contributed modules.
    • composer.json and composer.lock: Define your project’s dependencies.
    • vendor/: Managed by Composer, but sometimes included in full backups for quick restoration.
    • Configuration files (if using Configuration Management workflow): Typically stored in a directory like config/sync or sites/default/config/sync and should be version-controlled with Git.

3. Using Backup Modules (e.g., Backup and Migrate)

Section titled “3. Using Backup Modules (e.g., Backup and Migrate)”

The ‘Backup and Migrate’ module (contrib) allows you to perform database and file backups (limited scope for files) directly from the Drupal UI. It can also schedule backups. While convenient, for robust and comprehensive backups, especially of files, CLI methods or hosting provider tools are often preferred.

4. Using Drush for a Full Archive (Code, Files, DB)

Section titled “4. Using Drush for a Full Archive (Code, Files, DB)”

Drush can also create a full site archive:

drush archive:dump --destination=/path/to/backup/site-archive.tar.gz

This command bundles the codebase, public files directory, and a database dump into a single archive.

  • Regularity: Perform backups regularly, especially before updates or major changes.
  • Off-site Storage: Store backups in a separate, secure location (e.g., cloud storage, different server, external drive).
  • Testing: Periodically test your backups by restoring them to a development or staging environment to ensure they work.
  • Automation: Automate your backup process using cron jobs and scripts if possible.