备份 项目 mysql linux shell

#!/bin/sh
echo "backup 517play and mysql"
BACKUP_DIR=/var/www/Data_Backup/
DATE=`date '+%Y%m%d-%H%M'`
SOURCE=/root/aaa.log
TEMP517PLAY=517play
DISK517PLAY=${TEMP517PLAY}_$DATE.tar.gz
SQLNAME=${TEMP517PLAY}_sql_$DATE.tar.gz
if [ ! -d $BACKUP_DIR ];
then
mkdir -p "$BACKUP_DIR"
fi
scp -r $SOURCE $BACKUP_DIR/$TEMP517PLAY
if [ $?==0 ];then
cd $BACKUP_DIR
tar zcvf  $DISK517PLAY $TEMP517PLAY
echo "backup successful"
rm -rf $TEMP517PLAY


#"backup mysql"
USER=root
PASSWORD=root
DATABASE=mysql
mysqldump --default-character-set=utf8 -u$USER -p$PASSWORD $DATABASE >$TEMP517PLAY.sql
echo "mysql backup success!"
tar zcvf $SQLNAME $TEMP517PLAY.sql
rm -fr $TEMP517PLAY.sql


#remove 7 days file
find -ctime +7 -name "$TEMP517PLAY*"| xargs rm -rf
else
echo "backup fail"
fi

你可能感兴趣的:(Linux shell)