The two Bash shell scripts presented here work together automating the Drupal backup and restore process. They work "as is" for simple installations and can be customized for multisite or non-standard installations.
The scripts have two uses:
- Creating Drupal backups which can be restored to their original location
e.g., restore from a failed upgrade attempt or recover from a disk failure
- Staging data between Drupal configurations
e.g., backup a production instance and restore to a test instance
These scripts have been used successfully on and between Linux systems and on Windows systems using Cygwin.
A full Drupal backup requires data backups from both the database and file system. These two backups must then be tied to each other.
The backup script performs a file system backup using the tar command and a database backup using the mysqldump utility. The two backups are then combined into a single tar file. The tar is compressed and its file name includes the backup date.
The restore script reverses the process by unpacking the file and database backups from the container tar file and applying them to their respective targets.
The Drupal instance backed up or restored is specified by variables defined in the backup and restore scripts.
Usage notes and cautions
Detailed usage notes are provided for each script. The following points bear highlighting:
- The restore script has no safeguards against accidental restore. If you don't understand how it can destroy your system you are encouraged NOT to use it.
- The backup script backs up every file and directory in the Drupal root directory. If you have a hosted site with subdomain websites contained in subdirectories a backup of the main website directory will include the subdomain websites. For backups this will only bloat your backup file. For restores this could be disastrous, since you would be restoring the file systems for ALL of the website. If you have this kind of configuration you must customize the tar command to make a selective backup.
- These scripts make no provision to lock out users while the backup or restore is in progress.
- This script does not understand Drupal multisite configurations
- The backup script requires read access to all files/directories and the restore script requires read/write access. This is sometimes a problem in hosted configurations.
- Because the backup and restore is done in stages enough temporary space must be available for the intermediate files
- Some commands used in the scripts will vary between operating systems. You may have to tailor commands for your operating system.