A complete backup strategy for Drupal or Joomla needs to cover both the database (content, configuration, users) and the file system (uploaded media, custom code, configuration files). This guide covers a reliable approach for both platforms.
What to Back Up
- Database — content, configuration, user accounts
- Uploaded files/media — images, documents, and other user-uploaded content
- Custom code — custom modules/extensions, themes, and configuration files
Backing Up the Database
mysqldump -u backup_user -p'PASSWORD' drupal_db | gzip > /var/backups/drupal-db-$(date +%F).sql.gz
Substitute your actual database name (Drupal or Joomla) — the command structure is identical for both.
Backing Up Files
# Drupal
rsync -avz /var/www/drupal/web/sites/default/files/ /var/backups/drupal-files/
# Joomla
rsync -avz /var/www/joomla/images/ /var/backups/joomla-files/
Backing Up Configuration (Drupal-Specific)
Drupal's configuration management system lets you export configuration as YAML files, separate from the database — useful for version-controlling site configuration alongside code:
drush config:export
Automating the Backup Process
sudo nano /usr/local/bin/backup-cms.sh
#!/bin/bash
TIMESTAMP=$(date +%F)
mysqldump -u backup_user -p'PASSWORD' cms_db | gzip > /var/backups/cms-db-$TIMESTAMP.sql.gz
rsync -avz /var/www/cms/files/ /var/backups/cms-files/
find /var/backups -name "cms-db-*.sql.gz" -mtime +14 -delete
sudo crontab -e
0 2 * * * /usr/local/bin/backup-cms.sh
Storing Backups Off-Server
See How to Back Up to Object Storage (S3-Compatible) — essential for genuine disaster recovery, not just protection against accidental content deletion.
Restoring the Database
gunzip < cms-db-BACKUP_DATE.sql.gz | mysql -u user -p cms_db
Restoring Files
rsync -avz /var/backups/cms-files/ /var/www/cms/files/
sudo chown -R www-data:www-data /var/www/cms/files/
Restoring Drupal Configuration
drush config:import
Testing Restores Periodically
Restore a backup to a staging environment periodically to confirm backups are actually valid and complete — an assumption that backups "probably work" isn't a substitute for verifying it.
Before Any Major Update
Always take a fresh, verified backup immediately before applying core updates or installing new modules/extensions — these are the highest-risk moments for something going wrong.
Common Errors
Restored site shows database connection errors — verify the restored database credentials match what's configured in settings.php (Drupal) or configuration.php (Joomla) on the destination server.
Continue Reading
- How to Back Up to Object Storage (S3-Compatible)
- How to Secure a Drupal or Joomla Installation
- How to Optimize Performance for Drupal/Joomla on a VPS
Browse more articles in CMS Platforms Beyond WordPress.