[Bash][GNU/Linux] How to Backup your Drupal Site?

| | 1 min read

Backup! Backup! Backup! Always back up your Drupal site's code and database before you actually start making any changes to your site. Do you have access to the control panel? Cool! Go ahead and create a zip file of your entire site, export your db, download it to your local machine and you are done. Read on to know how to backup your Drupal site.

Open up a terminal window in your Linux box and type the following commands to get it done instantly.

At first create a backup directory to store the site's backup in the root folder.

$ sudo mkdir backup

How to create a Mysql dump?

$ mysqldump -u [username] -p[password] [dbname] > db.backup_20121004.sql

OR

$ mysqldump -u [username] -p [dbname] db.backup_20121004.sql

Here is an example of how you actually use this command and your database back up will be created at the same path.
E.g. mysqldump -u root -p example_db > db.backup_20121004.sql

How to create a back up of Files and folders?

Step 1: Compress files

$ tar -zcvpf files.backup_20121004.tar.gz /backup

If the directories require root permission then try the tar command using the sudo command as follows:

$ sudo tar -zcvpf files.backup_20121004.tar.gz /backup

Step 2: Securely copy the back up files to your machine

$ scp [filename] [username]@[host_name]:[destination_folder]

OR

$ scp [remote_username]@[remote_hostname]:/[path_to_remote]/[filename] [path_to_local]/[filename]

For more details try this command: $ man scp in the terminal.

Hope the article was helpful, please leave your feedback using the comments box below.