备份 项目 mysql linux shell

#!/bin/sh

echo"backup517playandmysql"

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

tarzcvf$DISK517PLAY$TEMP517PLAY

echo"backupsuccessful"

rm -rf $TEMP517PLAY

#"backupmysql"

USER=root

PASSWORD=root

DATABASE=mysql

mysqldump--default-character-set=utf8-u$USER-p$PASSWORD$DATABASE>$TEMP517PLAY.sql

echo"mysqlbackupsuccess!"

tarzcvf$SQLNAME$TEMP517PLAY.sql

rm -fr $TEMP517PLAY.sql

#remove7daysfile

find-ctime+7-name"$TEMP517PLAY*"|xargsrm-rf

else

echo"backupfail"

fi

相关推荐