#!/bin/sh
#
#NAME
#  tarbkup - Make backup copy of a file heirarchy using tar
#
#SYNOPSIS
#  tarbkup srcdir destdir
#
#DESCRIPTION
#  This little script uses tar(1) to make a backup copy of  a  directory  and
#  all its contents somewhere else in the file system. The destdir should not
#  be under the srcdir, or you'll fill all of the disk.
#
#  The main advantage to using tar instead of [s]cp is that tar handles links
#  correctly,  and  doesn't create multiple copies of what should be a single
#  multi-linked file.
#
#  This script mostly exists as a way to avoid figuring it out from the  "man
#  tar" command every time.
#
#BUGS
#  Symlinks will only work in the copy if they are relative; a symlink using
#  a full pathname will only work if the same name exists after the copy. If
#  the destdir is moved copied to another machine, this may not be true.
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>

if [ $# -ne 2 ];then echo Usage: $0 srcdir destdir; exit 1; fi
if [ ! -d $1 ];then echo $0: "No directory" $1; exit 2; fi
if [ ! -d $2 ];then mkdir $2; fi
if [ ! -d $2 ];then echo $0: "Can't make directory" $2; exit 3; fi

tar -cf - -C $1 . | tar xpf - -C $2

