#!/bin/shsvrname=имя_сервера
bkpdate=`date "+%Y%m%d"`
bkptime=`date "+%H%M%S"`
desthost=10.135.0.102
#destname=nas001k
destshare=/mnt/HD_a2/unix/имя_сервера
mountpoint=/mnt/nas001k
destdir=${bkpdate}_${svrname}
logpoint=${mountpoint}/.log/${svrname}.log
nagiospipe=/tmp/bkpstatus.nagios
gzip="/usr/bin/gzip"
echo 0 > ${nagiospipe}
umount -f $mountpoint 2>/dev/null 1>/dev/null
/sbin/mount_nfs ${desthost}:${destshare} ${mountpoint} 2>/dev/null 1>/dev/null
#/bin/mount -t nfs -O rsize=8192,wsize=8192,nolock ${desthost}:${destshare} $mountpoint 2>/dev/null 1>/dev/null
if [ ! -d ${mountpoint}/.check_mount ]; then
echo "NFS device not mounted! Trying to remount..."
umount $mountpoint 2>/dev/null 1>/dev/null
/bin/mount -t nfs -O rsize=8192,wsize=8192,nolock ${desthost}:${destshare} $mountpoint 2>/dev/null 1>/dev/null
#-- double check
if [ ! -d ${mountpoint}/.check_mount ]; then
echo "Something evil happening here..."
echo "check_mount dir deleted or cant mount NFS, "
echo "giving up!"
echo 0 > ${nagiospipe}
exit 0
fi;
fi
if ! mkdir ${mountpoint}/${bkpdate}; then
if [ -d ${mountpoint}/${bkpdate} ]; then
echo "Deleting -rf: ${mountpoint}/${bkpdate}"
rm -rf ${mountpoint}/${bkpdate}
else
echo "Something evil happening here..."
echo "cant create backup dir on NFS device!"
echo 0 > ${nagiospipe}
exit 0
fi
fi
echo "stage 1..."
echo "Starting backup process on $svrname" > ${logpoint}
echo "Date now: `date`" >> ${logpoint}
echo "==== $svrname ==========================================" >> ${logpoint}
mkdir ${mountpoint}/${bkpdate}
cd /back
rm /back/*gz
data=`date|awk '{print $2 $3}'`
echo "stage 2..."
tar -zcvf etc-${bkpdate}.tar.gz /etc 2>>${logpoint} 1>>${logpoint}
tar -zcvf root-${bkpdate}.tar.gz /root 2>>${logpoint} 1>>${logpoint}
tar -zcvf vardb-${bkpdate}.tar.gz /var/db 2>>${logpoint} 1>>${logpoint}
tar -zcvf varnamed-${bkpdate}.tar.gz /var/named 2>>${logpoint} 1>>${logpoint}
tar -zcvf usrlocaletc-${bkpdate}.tar.gz /usr/local/etc 2>>${logpoint} 1>>${logpoint}
#== rsync backup here
#==
echo "==== rsync /srv/ /mnt/nas001k/rsync_srv/ ======================="
/usr/bin/rsync -ap /srv/ /mnt/nas001k/rsync_srv/ 2>/dev/null 1>>${logpoint}
echo "stage 3..."
cd ${mountpoint}/${bkpdate}
cp /back/* .
cd /root/bin
echo "Backup task ended at: `date`" >> ${logpoint}
echo "==== $svrname ==========================================" >> ${logpoint}
#
# check of copying and taring need to do
#
echo 1 > ${nagiospipe}
cd /home
umount -f $mountpoint 2>/dev/null 1>/dev/null