- Linux Systems
- How To Backup And Restore Directory In Linux Command
This Page Contains information about How To Backup And Restore Directory In Linux Command By wallpaperama in category Linux Systems with 1 Replies. Last Upated: Mon Apr 20, 2015 
Sun Dec 28, 2008
backing up and restoring a directory in linux is easy. i wanted to put this here just incase anyone is insterested in knowing how to backup their wallpaper website. backing up with linux its nothing complicated, but if you dont have much practice with the unix shell commands, it can be overwhelming sometimes. i know it was for me, im getting use it to it, but from time to time, i want to know how i can do a full backup of my website. if you are used to backing up your website with ftp, that takes forever. how about if i told you that you can compress and backup your entire websites in just seconds.
for me, my website is about 5G full, so ftp just wont do. if i had to do a full backup, this will take me forever to ftp plus then another forever to download if you are poor like me and only have s slow dsl line.
so here it is, i wont bore you with my drama,, lets say i have want to compress my web directory, and the location is: /var/www/
in the /var/www/ is where i keep my website on my dedicated server. so to compress it i will compress it using gzip and tarball. the first command would be for me to change directory to the /var:
then once i am in /var i can tar my www/ directory and im going to call my backup file: backup-12-128-08-mydomain so this is the command i would do:
tar -pczf backup-12-128-08-mydomain.tar.gz www/
once it completes, you can to the list command to show that it created our file:
* the -la is to show details of the files, this way you can see the file size
ok now you can download the file with http instead of ftp
so lets say now that for some reason something went bad, and i want to restore to my backup, easy, to restore our backup file i would put our backup-12-128-08-mydomain.tar.gz file in the /var directory:
mv /var/www/public_html/downloads/backup-12-128-08-mydomain.tar.gz /var/backup-12-128-08-mydomain.tar.gz
this will move our backup-12-128-08-mydomain.tar.gz to the /var directory
now go back to the /var directory where we put our new backup file
then rename my old www/ to www-broken-12-28-08
mv www/ www-broken-12-28-08/
then i can restore the www/ with this command:
tar xvfz backup-12-128-08-mydomain.tar.gz
then you will see all your files and directories that you saved, start to load.