Friday, May 06, 2011

Shell Script FreeBSD Full / Incremental Tape Backup

#!/bin/sh
# A FreeBSD shell script to dump Filesystem with full and incremental backups to tape device connected to server.
# Tested on FreeBSD 6.x and 7.x - 32 bit and 64 bit systems.
# May work on OpenBSD / NetBSD.
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://www.cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
LOGGER=/usr/bin/logger
DUMP=/sbin/dump
# FSL="/dev/aacd0s1a /dev/aacd0s1g"
FSL="/usr /var"
NOW=$(date +"%a")
LOGFILE="/var/log/dumps/$NOW.dump.log"
TAPE="/dev/sa0"
 
mk_auto_dump(){
local fs=$1
local level=$2
local tape="$TAPE"
local opts=""
 
opts="-${level}uanL -f ${tape}"
# run backup
$DUMP ${opts} $fs
if [ "$?" != "0" ];then
$LOGGER "$DUMP $fs FAILED!"
echo "*** DUMP COMMAND FAILED - $DUMP ${opts} $fs. ***"
else
$LOGGER "$DUMP $fs DONE!"
fi
}
 
dump_all_fs(){
local level=$1
for f in $FSL
do
mk_auto_dump $f $level
done
}
 
init_backup(){
local d=$(dirname $LOGFILE)
[ ! -d ${d} ] && mkdir -p ${d}
}
 
init_backup
 
case $NOW in
Mon) dump_all_fs 0;;
Tue) dump_all_fs 1;;
Wed) dump_all_fs 2;;
Thu) dump_all_fs 3;;
Fri) dump_all_fs 4;;
Sat) dump_all_fs 5;;
Sun) dump_all_fs 6;;
*) ;;
esac > $LOGFILE 2>&1
 
 
 
Regards,
Sukhwinder Singh 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

There was an error in this gadget