BSD DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to BSD Subscribe to Newsletters

FreeBSD Basics Backing up Files with Tar

by Dru Lavigne
05/23/2002

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:

su
Password:
adduser

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:

su
Password:
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 Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com