BSD DevCenter
oreilly.comSafari Books Online.Conferences.


FreeBSD Basics Backing up Files with Tar

by Dru Lavigne

In my last article, I introduced the concept of archivers; today I would like to demonstrate the usage of the tar archiver.

Since we'll be backing up and restoring files, I recommend that you create a test user account to practice with until you are comfortable using the tar utility. On my system, I became the superuser and used the adduser command to create a test account named test:


I then followed the prompts to make a user called test.

I then wanted to quickly add a lot of subdirectories and files to this test user's home directory. Since I had the ports collection installed on my system, I copied over one of its subdirectories:

cp -r /usr/ports/www/ ~test/

I then changed the ownership of these files so they belonged to the test user:

chown -R test ~test/www/*

I now had a lot of files in a test directory to practice with. I then logged in as the test user and checked out the contents of my home directory:

ls -l
total 16
drwxr-xr-x  375 test  wheel  9728 May 11 09:53 www/

du -h | tail -2
 28M	./www
 28M	.

It looks like I have 28M worth of data to work with in my test directory.

In theory, tar can be as easy to use as this command:

tar c .

where the c means "create an archive" and the "." means "of the current directory." However, if you try this, you will probably get the same error message I did:

tar c .
tar: can't open /dev/sa0 : Permission denied

Aha, you may think; I'll try as the superuser:

tar c .
tar: can't open /dev/sa0 : Device not configured

Remember last week when I talked about tape devices? By default, the tar utility assumes that you want to backup to your first SCSI tape drive (/dev/sa0) which is great, if you happen to have one attached to your PC. If you don't, all is not lost. In Unix, a tape device is simply a file. So it is very easy to tell tar to create a backup to another file, whether that file be a different type of tape device, a floppy, another hard drive, another PC on the network, or an actual file somewhere on your system.

Pages: 1, 2, 3, 4

Next Pagearrow

Sponsored by: