Backing up your files with minimal disk space

A simple backup script that creates a copy of a given directory by using hard links instead of making copies of files. This results in substantial savings in disk space. Since the backup file has hard links, as you change your files in the working directory, the hard links always have the same content. So if you accidentally removed some files, you can get them from the backup directories since the system does not remove the contents of a file until all hard links to it are gone. Note that hard links cannot span across file systems.

#!/bin/sh
# backup2.sh

prog=`basename $0`
case $# in
0|1) echo 'Usage:' $prog '<original dir> <backup dir>'; exit 1;;
esac

orig=$1
backup=$2
if test -d $backup
then
    echo "Backup directory $backup already exists!"
    echo -n "Do you want to remove the backup directory $backup? (y/n)"
    read answer
    if test "$answer" = "y"
    then
        /bin/rm -fr $backup
    else
        exit 1
    fi
fi

mkdir  $backup
echo "Creating the directory tree"
find $orig -type d -exec mkdir $backup/"{}" \;

#make hard links to all regular files
echo "Creating links to the files"
find $orig -type f -exec ln {} $backup/"{}" \;

echo "done!"