When you backup your website you create copies of both the files and the database.
Back up files
Copy the contents of your Drupal directory to a directory outside your website, for example /tmp/drupalbackup. Below you find a number of possible ways to backup your files.
Copy all files to a backup directory
Copy all the files (including the .htaccess file) from your Drupal directory to the backup directory:
cp -rp /path/to/drupal_site /path/to/backup_dir
-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 xzpf 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 PASSWORD 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
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:
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
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]