Drupal backup

Posted on 2012-08-12
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

    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:
    ./ sites/default/settings.php > /path/to/backup_dir/database-backup.sql
    If you are running a version of Drupal 4.5 or older:
     ./ 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]


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
    Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now