Regular backups and the ability to migrate your Drupal site are essential for website management. In this guide, you will learn how to create professional backups and safely move your site to a new environment.

Why Backups Are Crucial

A good backup protects you against:

  • Hacked website due to malware
  • Accidentally deleted content
  • Failed updates
  • Server issues
  • Hosting migrations

Without a backup, you could lose months of work. Creating a backup only takes a few minutes.

Creating a Backup via Backup and Migrate

The Backup and Migrate module is the standard for Drupal backups.

Installing the Module

composer require drupal/backup_migrate

Activate via:

  1. Go to Extend
  2. Search for Backup and Migrate
  3. Check it and click Install

Creating a Database Backup

The database contains all your content and configuration:

  1. Go to Configuration and then Development
  2. Click on Backup and Migrate
  3. You are now on the Backup tab
  4. Select Default Database as the source
  5. Choose Download as the destination
  6. Click on Backup now
  7. Save the .sql.gz file securely

Creating a Full Backup

For a complete backup including files:

  1. Go to Backup and Migrate
  2. Select Entire Site as the source
  3. This creates a backup of:
    • Database
    • Public files (uploads)
    • Private files
  4. Click on Backup now

Setting Up Automatic Backups

Schedule regular backups:

  1. Go to Backup and Migrate and then Schedules
  2. Click on Add Schedule
  3. Configure:
    • Name: Daily backup
    • Source: Default Database or Entire Site
    • Destination: Server files or external storage
    • Frequency: Daily
    • Keep: 7 backups
  4. Save the schedule

The backups will be executed automatically via cron.

Backup via DirectAdmin

Combine with DirectAdmin backups for extra security.

Full Account Backup

  1. Log in to DirectAdmin
  2. Go to Account Manager and then Create/Restore Backups
  3. Select:
    • Domain files
    • Databases
    • Email (if applicable)
  4. Click on Create Backup
  5. Download the backup to your computer

Backing Up the Database Separately

  1. Go to Account Manager and then phpMyAdmin
  2. Select your Drupal database
  3. Click on Export
  4. Choose Quick for default settings
  5. Click on Go to download

Backup via SSH and Drush

For advanced users, Drush offers quick backups.

Database Backup with Drush

# Connect via SSH
cd ~/domains/jouwdomein.nl/public_html
# Create database backup
drush sql:dump > ~/backup/drupal-db-$(date +%Y%m%d).sql
# Compressed
drush sql:dump | gzip > ~/backup/drupal-db-$(date +%Y%m%d).sql.gz

Files Backup

# Backup of public files
tar -czf ~/backup/drupal-files-$(date +%Y%m%d).tar.gz sites/default/files
# Full site backup
tar -czf ~/backup/drupal-full-$(date +%Y%m%d).tar.gz .

Automating via Cron

Add to crontab:

# Daily backup at 03:00
0 3 * * * cd ~/domains/jouwdomein.nl/public_html && drush sql:dump | gzip > ~/backup/drupal-db-$(date +\%Y\%m\%d).sql.gz

Migrating a Drupal Site

During a migration, you move your site to a new server or domain.

Preparation

Before you start:

  1. Create a full backup
  2. Note the Drupal version
  3. Document installed modules
  4. Check PHP version requirements
  5. Schedule the migration outside peak hours

Step 1: Copying Files

Download all files from the old server:

# Via FTP/SFTP
# Download the entire Drupal folder
# Via SSH (on old server)
tar -czf drupal-site.tar.gz -C ~/domains/ouddomein.nl public_html

Upload to the new server:

# Unpack at the new location
tar -xzf drupal-site.tar.gz -C ~/domains/nieuwdomein.nl

Step 2: Migrating the Database

Export the database from the old server:

# Via Drush
drush sql:dump > drupal-db.sql
# Via phpMyAdmin
# Export and download as .sql

Import on the new server:

# Via Drush
drush sql:cli < drupal-db.sql
# Via phpMyAdmin
# Use the Import function

Step 3: Adjusting settings.php

Edit settings.php for the new environment:

$databases['default']['default'] = [
  'database' => 'nieuwe_database',
  'username' => 'nieuwe_user',
  'password' => 'nieuw_wachtwoord',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
];
// Update trusted hosts
$settings['trusted_host_patterns'] = [
  '^nieuwdomein\.nl$',
  '^www\.nieuwdomein\.nl$',
];

Step 4: Clearing Cache and Testing

After the migration:

# Clear all caches
drush cache:rebuild
# Run any updates
drush updatedb

Check:

  • Homepage loads correctly
  • Admin login works
  • Images are displayed
  • Forms work

Step 5: Updating URLs

If the domain changes, update the base URL:

  1. Check settings.php for hardcoded URLs
  2. Use Search and Replace for content:
  3. composer require drupal/search_replace_scanner
  4. Or via database:
  5. UPDATE node__body SET body_value = REPLACE(body_value, 'ouddomein.nl', 'nieuwdomein.nl');

Restoring a Backup

If you need to restore a backup:

Via Backup and Migrate

  1. Go to Configuration and then Backup and Migrate
  2. Click on the Restore tab
  3. Upload your backup file
  4. Select what you want to restore
  5. Click on Restore now

Via Command Line

# Restore database
drush sql:cli < backup.sql
# Restore files
tar -xzf drupal-files.tar.gz -C sites/default/files
# Clear cache
drush cache:rebuild

Backup Best Practices

Follow these guidelines:

Frequency

  • Active sites: Daily database backup
  • Static sites: Weekly backup
  • Before updates: Always create a backup

Storage

  • Keep backups in multiple locations
  • Use cloud storage (Google Drive, Dropbox)
  • Maintain at least 7 days of backups

Testing

  • Regularly test restoring backups
  • Use a staging environment for tests
  • Document the restoration process

Need Help?

We are here for you! Are you facing any issues or do you have questions? Our support team is happy to assist you personally. Send us a message via the ticket system - we usually respond within a few hours and are happy to help.