#!/bin/bash putcmd="scp" remotehost="drg@iceberg" remotedir="/vol1/drg/backup/drg" tmpdir="/tmp" datefmt="%F_%H-%M" # 2006-01-11_13-44 taropts="-jc" tarext="tar.bz2" cryptcmd="gpg -c" usage() { echo "usage: $0 [-c]" echo -e "\t-c - crypt file with ,,$cryptcmd''" exit } if [ ! $1 ]; then usage fi if [ "x$2" == "x-c" ]; then crypt=1 else crypt=0 fi dir="$1" if [ ! -d $dir ]; then echo "unfortunately $dir isn't a directory.." if [ -f $xir ]; then echo "but.. $dir is a file and i will backup it.." else usage fi fi dirname=`basename $dir` date=`date +$datefmt` archive="$dirname-$date.$tarext" tmparchive="$tmpdir/$archive-tmp" cmd="tar $taropts -f $tmparchive $dir" echo "executing '$cmd'..." $cmd if [ $crypt -eq 1 ]; then cmd="$cryptcmd $tmparchive" echo "executing '$cmd'..." $cmd rm -f $tmparchive tmparchive="$tmparchive.gpg" fi cmd="$putcmd $tmparchive $remotehost:$remotedir/$archive" echo "executing '$cmd'..." $cmd rm -f $tmparchive