[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Drupal backup

Posted on 2012-08-12
Medium Priority
Last Modified: 2012-08-13
I would like to make scheduled backups for the following in a Drupal installation:

Core files
Contributed modules

I am aware that the backup and migrate module handles scheduled backups for the database.

Would it be possible,in Linux, to establish cron jobs, that would compress core files and contributed module files, and make backup copies onto a separate hard drive on my server?

Can I please have an example of the command that would be issued?

Thanks for your answers.
Question by:netplus21
1 Comment
LVL 17

Accepted Solution

selvol earned 2000 total points
ID: 38285251
Create a cron job.
cp -rp /path/to/drupal_site /path/to/backup_dir

The option -rp means copy recursive and preserve permissions.
Put files in compressed archive

Alternatively, you can archive and compress all the files (including the .htaccess file) from your Drupal directory to the backup directory. From your Drupal directory execute:

tar czf drupalbackup.tgz /path/to/drupal_site/

If you want to check to make sure this worked use tar xzf drupalbackup.tgz to extract the files into a new directory.
Back up database

Before making a database backup, it is recommended to turn off cron jobs.

Mysqldump lets you create a copy of the database:

mysqldump -u USERNAME -p DATABASENAME > /path/to/backup_dir/database-backup.sql

The Drush command sql-dump creates a copy of the database. From your Drupal directory execute:

drush sql-dump > /path/to/backup_dir/database-backup.sql

Use drush help sql-dump for more information.

If you have installed the module Backup & Migrate you can use the drush command bam-backup. From your Drupal directory execute:

drush bam-backup
Drupal sql dump script (Drupal 6 and earlier)

The Drupal sql dump script will look at your Drupal settings file, automatically connect to the database, and make a backup of it.
If you are running a version of Drupal that is 4.6 or newer:
./drupalsqldump.sh sites/default/settings.php > /path/to/backup_dir/database-backup.sql
If you are running a version of Drupal 4.5 or older:
 ./drupalsqldump.sh includes/conf.php > /path/to/backup_dir/database-backup.sql
PostgreSQL dump

There several ways to do a database backup using PostgreSQL dump . E.g.,
pg_dump -U [user] -h [host] [databasename] > dump.sql
pg_dump -U [user] -W -h [host] [databasename] -F c > dump.pg_restore.format

The former you can restore by running the script with psql, the latter by using the pg_restore utility.

For huge databases, the second method is nice because it is automatically compressed. Alternatively, pipe to gzip:

pg_dump -U [user] -W -h [host] [databasename] | gzip -c > dump.sql.gz

and to restore: gunzip -c dump.sql.gz | psql [options]


Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since I am currently running into this issue right now as I type this, I though I would share my experiences with moving a ModX Revolution site from one server to another.  It is not an easy task, but can be accomplished rather easily. The first …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month19 days, 20 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question