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

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




Recommended for You

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

Sign up today to receive special discounts,
product alerts, and news from O'Reilly.
Privacy Policy >
View Sample Newsletter >
  • Youtube
  • http://www.youtube.com/OreillyMedia
  • Twitter
  • Subscribe
  • View All RSS Feeds >
O'Reilly Media

800-889-8969 or 707-827-7019
Monday-Friday 7:30am-5pm PT
©2011, O'Reilly Media, Inc.
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
  • About O'Reilly
  • Academic Solutions
  • Contacts
  • Customer Service
  • Careers
  • Press Room
  • Privacy Policy
  • Terms of Service
  • Writing for O'Reilly
  • Community
  • Authors
  • Forums
  • Membership
  • Newsletters
  • RSS Feeds
  • User Groups
  • More O'Reilly Sites
  • igniteshow.com
  • makerfaire.com
  • makezine.com
  • craftzine.com
  • labs.oreilly.com
  • Partner Sites
  • PayPal Developer Zone
  • O'Reilly Insights on Forbes.com