Home > Backing up on Unix/Linux using TAR

Backing up on Unix/Linux using TAR

Simple little guide to demonstrate how I used to backup my using tar
By 22/10/10 [Last Edited by Joseph 15/04/11]
BOOKMARK
LOGIN
REGISTER
Backing up on Unix/Linux Just a quick page to explain a commonly used method of backing up on Unix-type operating systems using TAR. I'm sure I am not the only one who finds that TAR is a really valuable tool, and I use it to back up this website over SSH. This quick demonstration is aimed at people who host their website on a Unix or Linux web server, and want to find a quick way of backing the entire site up.

First of all I SSH into my server using an SSH client such as PuTTY.

I am presented with a prompt such as:

[domain1783774@ssh-server ~]$

I am currently in my home folder, and my website resides in /htdocs so therefore, I will want to TAR the /htdocs folder. The c in cvzf tells TAR that I want to create a new TAR file from the beginning. The v tells TAR that I want it to show output (i.e. files which are being processed). The z tells TAR that I want to compress the final TAR file with gzip, and the f tells TAR that I am going to specify a filename for the final TAR file straight afterwards. The web.tgz is the file I am writing to, and htdocs is the directory I am reading from.

[domain1783774@ssh-server ~]$ tar cvzf web.tgz htdocs

You should see all the files being processed, and when finished, you will be presented with a prompt. We now want to be able to download this TAR file, so we will need to move it into the web root (htdocs)

[domain1783774@ssh-server ~]$ mv web.tgz ./htdocs/web.tgz

Now, point your web browser to http://www.mywebsitenamehere.com/web.tgz and you should be able to download the TAR file.

[domain1783774@ssh-server ~]$ rm ./htdocs/web.tgz

You will probably now want to delete this TAR file off the server, to save space and to stop others from downloading it.

Other useful Unix commands

cp - Copy a file from a to b
rename - Rename a file from a to b
mkdir - Make a new directory
dir - List files in a directory
cd - Change directory
clear - Clear the screen

Any DOS user should have no problem with using these commands, and work very similar to DOS