# tar cv /etc > etc.tar
The result is the same.
All files in the /etc
directory will be saved to a file named etc.tar
. With an impressive array of options (see the man page), tar
is quite flexible and powerful in combination with shell scripts. With the -z
option, it can even create and restore gzip
compressed archives, whereas the -j
option works with bzipp
ed files.
Creating Full and Incremental Backups with tar
If you want to create a full backup,
# tar cjvf fullbackup.tar.bz2 /
creates a bzip2
-compressed tarball (the j
option) of the entire system.
To perform an incremental backup, you must locate all the files that have been changed since the last backup. For simplicity, assume that you do incremental backups on a daily basis. To locate the files, use the find
command:
# find / -newer name_of_last_backup_file ! -a -type f -print
When run alone, find
generates a list of files systemwide and prints it to the screen. The ! -a -type
eliminates everything but regular files from the list; otherwise, the entire directory would be sent to tar
even if the contents were not all changed.
Pipe the output of the find command to tar
as follows:
# find / -newer name_of_last_backup_file ! -type d -print |\
tar czT- backup_file_name_or_device_name
Here, the T -
option gets the filenames from a buffer (where the -
is the shorthand name for the buffer).
NOTE
The tar
command can back up to a raw device (one with no file system) as well as a formatted partition. For example,
# tar cvzf /dev/hdd /boot /etc /home
backs up those directories to device /dev/hdd
(not /dev/hda1
, but to the unformatted device itself).
The tar
command can also back up over multiple floppy disks:
# tar czvMf /dev/fd0 /home
backs up the contents of /home
and spreads the file out over multiple floppies, prompting you with this message:
Prepare volume #2 for '/dev/fd0' and hit return:
Restoring Files from an Archive with tar
The xp
option in tar
restores the files from a backup and preserves the file attributes as well, and tar
creates any subdirectories it needs. Be careful when using this option because the backups might have been created with either relative or absolute paths. You should use the tvf
option with tar
to list the files in the archive before extracting them so that you know where they will be placed.
For example, to restore a tar
archive compressed with bzip2
,
# tar xjvf fedoratest.tar.bz2
To list the contents of a tar
archive compressed with bzip2
,
# tar tjvf fedoratest.tar.bz2
drwxrwxr-x paul/paul 0 2003-09-04 18:15:05 fedoratest/
-rw-rw-r-- paul/paul 163 2003-09-03 22:30:49
fedoratest/fedora_screenshots.txt
-rw-rw-r-- paul/paul 840 2003-09-01 19:27:59 fedoratest/fedora_guideline.txt
-rw-rw-r-- paul/paul 1485 2003-09-01 18:14:23 fedoratest/style-sheet.txt
-rw-rw-r-- paul/paul 931 2003-09-01 19:02:00 fedoratest/fedora_TOC.txt
Note that because the pathnames do not start with a backslash, they are relative path names and install in your current working directory. If they were absolute pathnames, they would install exactly where the paths state.
The GNOME desktop file archiving graphical application File Roller ( file-roller
) views, extracts, and creates archive files using tar
, gzip
, bzip
, compress
, zip
, rar
, lha
, and several other compression formats. Note that File Roller is only a front end to the command-line utilities that actually provide these compression formats; if they are not installed, File Roller cannot use that format.
CAUTION
File Roller does not complain if you select a compression format that is not supported by installed software until after you attempt to create the archive. Install any needed compression utilities first.
File Roller is well integrated with the GNOME desktop environment to provide convenient drag-and-drop functionality with the Nautilus file manager. To create a new archive, select Archive, New to open the New Archive dialog box and navigate to the directory where you want the archive to be kept. Type your archive's name in the Selection: /root text box at the bottom of the New Archive dialog box. Use the Archive type drop-down menu to select a compression method. Now, drag the files that you want to be included from Nautilus into the empty space of the File Roller window, and the animated icons will show that files are being included in the new archive. When you are finished, a list of files will be shown in the previously blank File Roller window (see Figure 13.1). To save the archive, simply select Archive, Close. Opening an archive is as easy as using the Archive, Open dialog to select the appropriate archive file.
FIGURE 13.1 Drag and drop files to build an archive with the GNOME File Roller.
The KDE Archiving Tools (KDE ark
and kdat
)
Fedora provides you with the KDE ark
and kdat
GUI tools for backups; they are installed only if you select the KDE desktop during installation. Archiving has traditionally been a function of the system administrator and has not been seen as a task for the individual user, so no elaborate GUI was believed necessary. Backing up has also been seen as a script-driven, automated task in which a GUI is not as useful.
You launch ark
from the command line. It is integrated with the KDE desktop (as File Roller is with GNOME), so it might be a better choice if you use KDE. This application provides a graphical interface to viewing, creating, adding to, and extracting from archived files as shown in Figure 13.2. Several configuration options are available with ark
to ensure its compatibility with MS Windows. You can drag and drop from the KDE desktop or Konqueror file browser to add or extract files, or you can use the ark
menus.
FIGURE 13.2 Here, the contents of a . zip
file containing some JPEGs are displayed.
As long as the associated command-line programs are installed, ark can work with tar, gzip, bzip2, zip, and lha files (the latter four being compression methods used to save space by compaction of the archived files).
Existing archives are opened after the application itself has launched. You can add files and directories to the archive or delete them from the archive, as shown in Figure 13.3. After opening the archive, you can extract all its contents or individual files. You can also perform searches, using patterns (all *.jpg
files, for example) to select files.
FIGURE 13.3 The opening view of ark
presented as a simple GUI browser. Here, several files are being selected to add to the new archive.
Читать дальше