backup.sh
[quote]#!/bin/sh
USER=root
PASSWORD=admin
DATABASE=cms
WEBMASTER=XX@qq.com
CMS_DIR=/usr/apache-tomcat/webapps/cms
BACKUP_DIR=/var/wtcsg/Data_Backup/mysql/
BACKUP_DIR_TOMCAT=/var/wtcsg/Data_Backup/tomcat/
LOGFILE=/var/wtcsg/Data_Backup/mysql/data_backup.log
#DATE=date +%Y%m%d-%H%M
DATE=$(date +%Y%m%d)
DUMPFILE=DATE
OPTIONS=" [color=red]--opt --host=127.0.0.1 -u$USER -p$PASSWORD -R --triggers --single-transaction --flush-logs --database $DATABASE[/color] "
if [ ! -d $BACKUP_DIR ] ;
then
mkdir -p "$BACKUP_DIR"
fi
if [ ! -d $BACKUP_DIR_TOMCAT ][ $? == 0 ]; then
echo "[$ARCHIVE] Backup_mysql Successful!" >> $LOGFILE
fi
echo " " >> $LOGFILE
echo " " >> $LOGFILE
echo "----------------" >> $LOGFILE
echo "BACKUP_TOMCAT DATE:" $(date +"%y-%m-%d %H:%M:%S") >> $LOGFILE
echo "---------------- " >> $LOGFILE
#cp -rf /usr/apache-tomcat/webapps/cms $BACKUP_DIR_TOMCAT
cd $BACKUP_DIR_TOMCAT
[color=red]tar -czf cms$(date +%F).tar.gz $CMS_DIR[/color]
#cd /usr/apache-tomcat/webapps/cms
#tar -czf BACKUP_DIR_TOMCATcms$(date +%F).tar.gz $CMS_DIR
echo "[$ARCHIVE] Backup_tomcat Successful!" >> $LOGFILE
echo "Backup Process Done"[/quote]
--------------------------
--------------------------
--------------------------
----------------------
[quote]#!/bin/sh
USER=root
PASSWORD=admin
DATABASE=cms
WEBMASTER=XX@qq.com
CMS_DIR=/usr/apache-tomcat/webapps/cms
BACKUP_DIR=/var/wtcsg/Data_Backup/mysql/
BACKUP_DIR_TOMCAT=/var/wtcsg/Data_Backup/tomcat/
LOGFILE=/var/wtcsg/Data_Backup/mysql/data_backup.log
#DATE=date +%Y%m%d-%H%M
DATE=$(date +%Y%m%d)
DUMPFILE=DATE
OPTIONS=" [color=red]--opt --host=127.0.0.1 -u$USER -p$PASSWORD -R --triggers --single-transaction --flush-logs --database $DATABASE[/color] "
if [ ! -d $BACKUP_DIR ] ;
then
mkdir -p "$BACKUP_DIR"
fi
if [ ! -d $BACKUP_DIR_TOMCAT ][ $? == 0 ]; then
echo "[$ARCHIVE] Backup_mysql Successful!" >> $LOGFILE
fi
echo " " >> $LOGFILE
echo " " >> $LOGFILE
echo "----------------" >> $LOGFILE
echo "BACKUP_TOMCAT DATE:" $(date +"%y-%m-%d %H:%M:%S") >> $LOGFILE
echo "---------------- " >> $LOGFILE
#cp -rf /usr/apache-tomcat/webapps/cms $BACKUP_DIR_TOMCAT
cd $BACKUP_DIR_TOMCAT
[color=red]tar -czf cms$(date +%F).tar.gz $CMS_DIR[/color]
#cd /usr/apache-tomcat/webapps/cms
#tar -czf BACKUP_DIR_TOMCATcms$(date +%F).tar.gz $CMS_DIR
echo "[$ARCHIVE] Backup_tomcat Successful!" >> $LOGFILE
echo "Backup Process Done"[/quote]
--------------------------
chmod +x backup.sh //授权
--------------------------
vi /etc/crontab // 定时服务
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
--------------------------
service crond restart
----------------------