Section 38.3 explains the minimal basics of using tar to make backups, but there are lots of variations that can be very useful.
To create a tar archive for copying to another disk or another machine:
% tar cvf 20020214-book.tar ./book
tar 's c option stands for create, v for verbose, and the f option for file. 20020214-book.tar is the new archive file to create, and ./book says to archive the directory book in the current directory. Once you have an archive, you might want to compress it to save space. gzip and bzip2 are your best bets. (I use bzip2 here largely because it tends to give better compression, but be aware that gzip is more widely available and thus may be safer for backups.) You can compress it once you've made it:
% ls -l 20020214-book.tar -rw-r--r-- 1 deb deb 19415040 Feb 14 23:15 20020214-book.tar % bzip2 20020214-book.tar % ls -l 20020214-book.tar.bz2 -rw-r--r-- 1 deb deb 4033775 Feb 14 23:15 20020214-book.tar.bz2
Or you can compress it as you make it. GNU tar supports gzip compression on the fly with the z or - -gzip options and bzip2 compression on the fly with the - -bzip2 option, or you can pipe into gzip or bzip2:
% tar czvf 20020214-book.tar.gz ./book % tar cvf 20020214-book.tar.bz2 --bzip2 ./book % tar cvf - ./book | bzip2 > 20020214-book.tar.bz2
Section 39.2 and Section 39.3 have more information on using tar.
You can get more protection from certain kinds of mishaps by using a version control system like RCS (Section 39.5) or CVS (Section 39.7) to save every version of a file you are updating frequently. While it doesn't protect you from disk crashes, a version control system provides the ability to back up to a previous version if something gets changed or deleted incorrectly.
-- DJPH
Copyright © 2003 O'Reilly & Associates. All rights reserved.