Sunday, November 01, 2009

Simple backup on Ubuntu

Doing a basic backup using Linux isn't hard. In fact, it's a simple command away.

~$ tar cjvf foo.tar.bz2 bar

The above command will create a tarball foo.tar.bz2 containing bar. bar can be a single file or a folder. If it's a folder, tar will recursively add any files and folders it finds inside.

Here's what the options mean (as written in the manpage):

-c, --create
              create a new archive

-f, --file [HOSTNAME:]F
              use  archive  file or device F (otherwise value of TAPE environ‐
              ment variable; if unset, "-", meaning stdin/stdout)

-j, --bzip2
              filter archive through bzip2,  use  to  decompress  .bz2  files.
              WARNING:  some previous versions of tar used option -I to filter
              through bzip2.  When writing scripts, use --bzip2 instead of  -j
              so that both older and newer tar versions will work.

-v, --verbose
              verbosely list files processed

If you prefer gzip then replace j with z. You can also add more than one file or folder simultaneously easily.

~$ tar cjvf foo.tar.bz2 bar1 bar2 bar3

For those not comfortable with the terminal, Ubuntu's archives feature a few backup tools like Simple Backup Restore, Deja Dup Backup and File Backup Manager although I haven't tried any of those.

With the release of Karmic, it's a good thing to do a backup of your personal files whether you plan to upgrade or reformat.

A restore is equally simple (x means extract):

~$ tar xvjf foo.tar.bz2

or, for gzip archives:

~$ tar zxvf foo.tar.gz