This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.
Title
Poor Man's Backup with <c>tar</c>
Description
The application <c>tar</c> is ubiquitous in the Unix/Linux world. It rolls multiple files and directories into a single "tarball", which can be transferred more easily and expanded at its destination. A single option, <c>-z</c> applies a compression to the resulting tarball, giving the file the by now well-known extension <c>.tar.gz</c> (for tar-balled <i>and</i> g-zipped). Extracting this file involves two operations, in which first the compression is removed and then the tarball unrolled.
The easiest way to back up a folder (like a home directory) is using the following command:
<code>tar -czf marco_backup.tar.gz /home/marco/</code>
<h>Tarring "dotted" or hidden files</h>
However, this fails to include those most useful of files: the hidden files, which begin with a dot (".") on Unix/Linux<fn>. Adding a star to the command, as shown below, fails to have any impact:
<code>tar -czf marco_backup.tar.gz /home/marco/*</code>
In order to pick up all files, hidden and visible, you have to use the dot (".") from regular expression syntax, which <c>tar</c> interprets as grab-everything-and-I-mean-everything-from-this-folder-and-any-folders-below-it.
<code>tar -czf marco_backup.tar.gz /home/marco/.</code>
Once the hidden files are in the tarball, they are extracted with all other files when the archive is expanded to its destination---without any special syntax tricks. To expand an archive, navigate to its directory and execute the following command:
<code>tar -zxf marco_backup.tar.gz</code>
<h><c>tar</c> command line switches</h>
Here's a rundown of the most useful command line switches:
<ul>
<b><c>v</c></b> -- Runs the command in verbose mode, showing the files and directories that it's zipping or unzipping. If you're tarring a big folder, it's best to leave this switch off.
<b><c>c</c></b> -- Indicates that <c>tar</c> should create a new archive.
<b><c>x</c></b> -- Indicates that <c>tar</c> should create a new archive.
<b><c>z</c></b> -- Applies compression to the tarball after it has been created.
<b><c>f</c></b> -- Indicates that the first argument is the name of the file to which it should store or from which it should extract the tarball/archive. This must be the last switch before the filename itself.
</ul>
<hr>
<ft>In particular, the Courier IMAP server stores its email in mailboxes, each of which begin with a dot. Running a backup with <c>tar</c> running in standard mode backs up almost <i>no</i> mails whatsoever.</ft>