[root@PEK1-VMS-xxx ~]# crontab -l

30 23 * * * /bin/sh /opt/shell/wikibackup.sh >/dev/null 2>&1
[root@PEK1-VMS-03 ~]# cat /opt/shell/wikibackup.sh
#!/bin/bash
#################################
#       Athor:                  #
#       Date:22/3/2016          #
#       About:wiki_bakup        #
#################################

USER=root
PASSWD=xxxxxxxxxxx

# cur time
DATE=`date +%Y-%m-%d`

# localhost backup time
OLDDATE=`date +%Y-%m-%d -d '-3 days'`

MYSQLDUMP=/usr/bin/mysqldump
SOCKET=/var/lib/mysql/mysql.sock
BACKDIR=/data/wikibak
SOBACKDIR=/opt/atlassian
SOUBACKDIR=/etc/init.d/confluence1
WIKI_PREFIX=confluence

RSYBACKDIR=/data/pekdc1_backup
RSYHOST=10.254.xxx.xxxx
RSYUSER=webbak
RSYPASS=webbak

[ -d ${BACKDIR} ] || mkdir -p ${BACKDIR}
[ -d ${BACKDIR}/${WIKI_PREFIX}${DATE} ] || mkdir ${BACKDIR}/${WIKI_PREFIX}${DATE}
[ -f ${BACKDIR}/${WIKI_PREFIX}${DATE}.tar.gz ] || rm -rf ${BACKDIR}/${WIKI_PREFIX}${DATE}.tar.gz
[ ! -d ${BACKDIR}/${WIKI_PREFIX}${OLDDATE} ] || rm -rf ${BACKDIR}/${WIKI_PREFIX}${OLDDATE}
[ ! -f ${BACKDIR}/${WIKI_PREFIX}${OLDDATE}.tar.gz ] || rm -rf ${BACKDIR}/${WIKI_PREFIX}${OLDDATE}.tar.gz

for DBNAME in mysql confluence
do
${MYSQLDUMP} -S ${SOCKET} -u ${USER} -p${PASSWD} -e -f --single-transaction ${DBNAME} | gzip > ${BACKDIR}/${WIKI_PREFIX}${DATE}/${DBNAME}-backup-${DATE}.sql.gz
# echo "${DBNAME} has been backup successful."
sleep 5
done

tar -czPf ${BACKDIR}/${WIKI_PREFIX}${DATE}.tar.gz ${SOBACKDIR} ${SOUBACKDIR}
tar -zcvf  ${BACKDIR}/atlassian_confluence.home.${DATE}.gz --exclude=/var/atlassian/application-data/confluence/backups  /var/atlassian




if [ $? -eq 0 ];then
        /usr/bin/rsync -avzP --delete $BACKDIR root@10.254.xxx.xxx:$RSYBACKDIR
fi

# clear log file for 3 day ago
# find $BACKDIR -mtime +3 -type f | xargs rm -rf
find $BACKDIR -mtime +2 | xargs rm -rf
[root@PEK1-VMS-xxx ~]#
文档更新时间: 2020-02-23 14:37   作者:月影鹏鹏