Dashboard > Public Content > ... > LinuxShell > PoorMansBackup
  Public Content Log In   View a printable version of the current page.  
  PoorMansBackup
Added by James Richardson, last edited by James Richardson on Jul 10, 2006  (view change)
Labels: 
(None)

Can't afford a proper backup agent?

#!/bin/bash

NAME=`id -un`

if [ $NAME != root ]
then
    echo "$0 This command must be run as root"
    exit 1
fi

BACKUP=/data/backup

DIRS="/data/mail /data/imap"

DATE=`date +%Y%m%d`

BACKUP_DIR=$BACKUP/$DATE

if [ ! -e $BACKUP_DIR ]
then
    mkdir -p $BACKUP_DIR
fi

CWD=`pwd`

for dir in $DIRS
do
  start=`date`
  echo -n "$start $dir    "
  base=`basename $dir`
  cd $dir/..
  destfilename=`echo $dir | sed -e 's/\//_/g'`
  destfile=$BACKUP_DIR/$destfilename.tar.gz
  tar cpzf $destfile $base
  ls -lh $destfile
  cd $CWD
done

date

touch $BACKUP_DIR/.finished
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators