[root@centos ~]# vi backup.shソス@ソスソスソス@ソスoソスbソスNソスAソスbソスvソスXソスNソスソスソスvソスgソス成
#!/bin/bash
#
# ソスソスソス[ソスJソスソスソスソスソスナバソスbソスNソスAソスbソスv
#
LANG=C
#
# ソスン抵ソスJソスn
#
# ソスoソスbソスNソスAソスbソスvソスホ象ソスソスXソスgソスソス
# ソスソスソスoソスbソスNソスAソスbソスvソスホ象ゑソスソスtソスソスソスpソスXソスナ記ソスqソスソスソスソスソスソスソスXソスg
BACKUPLIST=/root/backuplist
[ ! -s ${BACKUPLIST} ] && echo "${BACKUPLIST} is not found" && error_exit
# ソスoソスbソスNソスAソスbソスvソスホ象外ソスソスソスXソスgソスソス
# ソスソスソスoソスbソスNソスAソスbソスvソスホ象外ソスソスソスtソスソスソスpソスXソスナ記ソスqソスソスソスソスソスソスソスXソスg
BACKUPNOLIST=/root/backupnolist
# ソスoソスbソスNソスAソスbソスvソスソスfソスBソスソスソスNソスgソスソスソスソス
BACKUPDIR=/backup
mkdir -p ${BACKUPDIR}
# ソスoソスbソスNソスAソスbソスvソスロ托ソスソスソスソス辮
# ソスソスソスソスソスソスソスソスソスソスソスワめゑソスソス゚具ソスソスソスソスoソスbソスNソスAソスbソスvソスソスロ托ソスソスソスソス髏「ソス辮
# ソスソスソス゚具ソスソスソスソスoソスbソスNソスAソスbソスvソスソスロ托ソスソスソスソスネゑソスソス鼾ソスソス1ソスソスソスwソス閧キソスソス
BACKUPGEN=1
# ソステ搾ソスソスソスソスEソスソスソスソスソスソスソスpソスXソスtソスソスソス[ソスY
# ソスソスソスwソス閧ェソスネゑソスソスニゑソスソスヘ暗搾ソスソスソスソスソスソスネゑソス
PASS=''
#
# ソスン抵ソスIソスソス
#
# ソス繽茨ソスソスソスヨ撰ソスソスソス`
cleanup () {
rm -rf ${TMPBACKUPTO}
rm -f ${TMPBACKUPNOLIST}
rm -f ${BACKUPLOG}
}
# ソスル擾ソスIソスソスソスソスソスソスソスヨ撰ソスソスソス`
error_exit () {
logger -t `basename ${0}` "backup aborted."
cleanup
exit 1
}
# ソスoソスbソスNソスAソスbソスvソスtソス@ソスCソスソスソスソスソスoソスbソスNソスAソスbソスvソスホ象外ソスソスソスXソスgソスノ追会ソス
# ソスソスソスoソスbソスNソスAソスbソスvソスtソス@ソスCソスソスソスソスソスフゑソスソスoソスbソスNソスAソスbソスvソスソスソスネゑソスソス謔、ソスノゑソスソスソス
TMPBACKUPNOLIST=`mktemp`
[ -s ${BACKUPNOLIST} ] && cat ${BACKUPNOLIST} > ${TMPBACKUPNOLIST}
echo "${BACKUPDIR}/*backup.tar.bz2" >> ${TMPBACKUPNOLIST}
# ソスOソスソスoソスbソスNソスAソスbソスvソスソスソスソスソスlソス[ソスソス
cd ${BACKUPDIR}
OLDBACKUPFILE=`ls backup.tar.bz2* 2>/dev/null`
if [ -f ${OLDBACKUPFILE} ]; then
TIMESTAMP=`ls --full-time ${OLDBACKUPFILE}|awk '{print $6}'|tr -d -`
mv ${BACKUPDIR}/${OLDBACKUPFILE} ${BACKUPDIR}/${TIMESTAMP}${OLDBACKUPFILE} > /dev/null 2>&1
fi
# ソスoソスbソスNソスAソスbソスvソスソスソスs
logger -t `basename ${0}` "backup started."
TMPBACKUPTO=`mktemp -d`
for i in `cat ${BACKUPLIST}`
do
rsync -a -R --exclude-from=${TMPBACKUPNOLIST} $i ${TMPBACKUPTO}
if [ $? -ne 0 ]; then
# ソスoソスbソスNソスAソスbソスvソスル常時ソスソスrootソスソスソスノ鯉ソスソスハゑソスソスソスソス[ソスソスソスハ知ソスソスソスソス
reason="ソスoソスbソスNソスAソスbソスvソスtソス@ソスCソスソスソスWソスソス(rsync)ソスソスソスs"
echo ${reason} | mail -s "BACKUP NG(`echo ${reason} | nkf -M`)" root
error_exit
fi
done
BACKUPLOG=`mktemp`
tar -cjvf $BACKUPDIR/backup.tar.bz2 ${TMPBACKUPTO} > ${BACKUPLOG} 2>&1
code=$?
if [ ${code} -ne 0 ]; then
# ソスoソスbソスNソスAソスbソスvソスル常時ソスソスrootソスソスソスノ鯉ソスソスハゑソスソスソスソス[ソスソスソスハ知ソスソスソスソス
reason="ソスoソスbソスNソスAソスbソスv(tar)ソスソスソスs"
cat ${BACKUPLOG} | mail -s "BACKUP NG(`echo ${reason} | nkf -M`)" root
rm -f ${BACKUPDIR}/backup.tar.bz2
error_exit
fi
cat ${BACKUPLOG} | logger -t `basename ${0}`
logger -t `basename ${0}` "backup ended."
# ソスoソスbソスNソスAソスbソスvソステ搾ソスソスソス(ソステ搾ソスソスソスソスEソスソスソスソスソスソスソスpソスXソスtソスソスソス[ソスYソスwソス闔橸ソスフゑソス)
if [ ! -z ${PASS} ]; then
logger -t `basename ${0}` "backup encrypt started."
mkdir -p ${HOME}/.gnupg
echo ${PASS}|gpg --passphrase-fd 0 --batch -c ${BACKUPDIR}/backup.tar.bz2 > /dev/null 2>&1
code=$?
if [ ${code} -ne 0 ]; then
# ソスoソスbソスNソスAソスbソスvソスル常時ソスソスrootソスソスソスノ鯉ソスソスハゑソスソスソスソス[ソスソスソスハ知ソスソスソスソス
reason="ソスoソスbソスNソスAソスbソスvソステ搾ソスソスソス(gpg)ソスソスソスs"
cat ${BACKUPLOG} | mail -s "BACKUP NG(`echo ${reason} | nkf -M`)" root
rm -f ${BACKUPDIR}/backup.tar.bz2*
error_exit
fi
rm -f ${BACKUPDIR}/backup.tar.bz2
logger -t `basename ${0}` "backup encrypt ended."
fi
# ソスoソスbソスNソスAソスbソスvソスロ托ソスソスソスソスソス超ゑソスソスソスソステゑソスソスoソスbソスNソスAソスbソスvソスソスソス除
if [ $(ls ${BACKUPDIR}/*backup.tar.bz2*|wc -l) -gt ${BACKUPGEN} ]; then
OLDBACKUPCNT=`expr $(ls ${BACKUPDIR}/*backup.tar.bz2*|wc -l) - ${BACKUPGEN}`
for file in `ls -t ${BACKUPDIR}/*backup.tar.bz2*|tail -n ${OLDBACKUPCNT}`
do
rm -f $file
done
fi
# ソス繽茨ソスソス
cleanup
exit 0
[root@centos ~]# chmod 700 backup.shソス@ソスソスソス@ソスoソスbソスNソスAソスbソスvソスXソスNソスソスソスvソスgソスヨ趣ソスソスsソスソスソスソスソスtソスソス
|