How to backup a site using SSH?

In many cases it is advisable to create a complete backup of your site. In that way you will be able to restore a working copy if anything should go wrong, e.g. during an upgrade or similar. This article explains how to create a compressed archive of all your files via SSH.

After you have logged in to SSH, navigate to your home directory. To do this, type the following at the command prompt followed by [enter]:

cd ~

Now, type the following command to create the backup:

tar -zcf backup.tar.gz directory/to/backup/

Replace directory/to/backup/ with the name of the directory containing you files. The backup will be stored in 'backup.tar.gz'. E.g., to backup your entire web root, type:

tar -zcf backup.tar.gz public_html

Note: if your site is database-driven, make sure to also backup your database.

Click here for information on how to restore your website from a backup.

Was this answer helpful?