Archive An Entire Web Folder Using Tar Via SSH

Before performing any major operations on a site it is great to have the reassurance that you have a complete back up. ALWAYS do this when taking over a new project and, even though you may have your files in a .git or svn system it can be a real livesaver to just turn time back a few minutes if your major update goes pear shaped. One of my colleagues refers to this as the “get out of jail free card”. You can also use this to take a copy of the entire site when you want to move it – to a development server for example.

To back up and entire folder use this command:

tar -cvzf backupfilename.tar.gz /path-to-backup

e.g.

(from inside the www/html/ folder)

tar -cvzf lazybackup.tar.gz  lazywebdev

 

This will recursively plod through your site and compress everything, including the file structure and permissions into a single file.  You can then copy this somewhere else for safe keeping or just leave it for a while in case you need it.  These files can be large though.

If you want to restore the backup you have made, navigate to the place you made it from (in my example  www/html) or where you want it, and run:

tar -xvzf backupfilename.tar.gz

e.g.

tar -xvzf lazybackup.tar.gz

 

 

 

 

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *