mysql数据库备份脚本-创新互联
#!/bin/bash
创新互联建站是一家专业提供鹿邑企业网站建设,专注与成都网站制作、成都网站建设、外贸营销网站建设、成都h5网站建设、小程序制作等业务。10年已为鹿邑众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。Begin=date +"%Y年%m月%d日 %H:%M:%S"
BakDir=/home/backup/backup
LogFile=/home/backup/backup/bak.log
Date=date +%Y%m%d
cd $BakDir
DumpFile=$Date.sql
BZDumpFile=$Date.sql.tar.bz2
/usr/bin/mysqldump -u数据库登录帐号 -p数据库密码 --all-databases > $DumpFile
/bin/tar jvcf $BZDumpFile $DumpFile
/bin/rm $DumpFile
openssl enc -k 备份加密密码 -aes-128-ecb -e -in $BZDumpFile -out $BZDumpFile-aes
#-d 解密
/bin/rm $BZDumpFile
Last=date +"%Y年%m月%d日 %H:%M:%S"
echo "">>$LogFile
echo "---------fullybak--------">>$LogFile
echo "$BZDumpFile-aes copying">>$LogFile
echo 开始:$Begin 结束:$Last $BZDumpFile-aes succ >> $LogFile
#!/bin/bash
Begin=date +"%Y年%m月%d日 %H:%M:%S"
BakDir=/home/backup/backup
LogFile=/home/backup/backup/bak.log
Date=date +%Y%m%d
cd $BakDir
echo "">>$LogFile
echo "---------scp--------">>$LogFile
if (test -e $Date.sql.tar.bz2-aes)
then
scp $BakDir/$Date.sql.tar.bz2-aes backup@10.0.0.22:/home/backup/backup55
if [ "$?" = "0" ]
then
echo "$Date.sql.tar.bz2-aes sending...">>$LogFile
else
echo "scp failed...">>$LogFile
fi
else
echo "$Date.sql.tar.bz2-aes not exist!">>$LogFile
fi
if (test -e $Date.tar.bz2-aes)
then
scp $BakDir/$Date.tar.bz2-aes backup@10.0.0.22:/home/backup/backup55
if [ "$?" = "0" ]
then
echo "$Date.tar.bz2-aes sending...">>$LogFile
else
echo "scp failed...">>$LogFile
fi
else
echo "$Date.tar.bz2-aes not exist!">>$LogFile
fi
Last=date +"%Y年%m月%d日 %H:%M:%S"
echo 开始:$Begin 结束:$Last succ >> $LogFile
#!/bin/bash
Begin=date +"%Y年%m月%d日 %H:%M:%S"
LogFile=/home/backup/backup/bak.log
BakDir=/home/backup/backup
cd $BakDir
oldBakDir0=date -d '-35 days' +%Y%m%d
.tar.bz2-aes
oldBakDir1=date -d '-34 days' +%Y%m%d
.tar.bz2-aes
oldBakDir2=date -d '-33 days' +%Y%m%d
.tar.bz2-aes
oldBakDir3=date -d '-32 days' +%Y%m%d
.tar.bz2-aes
oldBakDir4=date -d '-31 days' +%Y%m%d
.tar.bz2-aes
oldBakDir5=date -d '-30 days' +%Y%m%d
.tar.bz2-aes
oldBakDir6=date -d '-29 days' +%Y%m%d
.tar.bz2-aes
oldBakFile=date -d '-35 days' +%Y%m%d
.sql.tar.bz2-aes
Date=date +%Y%m%d
GZDumpFile=$Date.sql.tar.bz2-aes
echo "">>$LogFile
echo "---------rm--------">>$LogFile
if (test -e $GZDumpFile)
then
if (test -e $oldBakDir0)
then
rm -rf $oldBakDir0
echo "delete increased sql $oldBakDir0" >> $LogFile
else
echo "$oldBakDir0 not exist!" >> $LogFile
fi
if (test -e $oldBakDir1)
then
rm -rf $oldBakDir1
echo "delete increased sql $oldBakDir1" >> $LogFile
else
echo "$oldBakDir1 not exist!" >> $LogFile
fi
if (test -e $oldBakDir2)
then
rm -rf $oldBakDir2
echo "delete increased sql $oldBakDir2" >> $LogFile
else
echo "$oldBakDir2 not exist!" >> $LogFile
fi
if (test -e $oldBakDir3)
then
rm -rf $oldBakDir3
echo "delete increased sql $oldBakDir3" >> $LogFile
else
echo "$oldBakDir3 not exist!" >> $LogFile
fi
if (test -e $oldBakDir4)
then
rm -rf $oldBakDir4
echo "delete increased sql $oldBakDir4" >> $LogFile
else
echo "$oldBakDir4 not exist!" >> $LogFile
fi
if (test -e $oldBakDir5)
then
rm -rf $oldBakDir5
echo "delete increased sql $oldBakDir5" >> $LogFile
else
echo "$oldBakDir5 not exist!" >> $LogFile
fi
if (test -e $oldBakDir6)
then
rm -rf $oldBakDir6
echo "delete increased sql $oldBakDir6" >> $LogFile
else
echo "$oldBakDir6 not exist!" >> $LogFile
fi
if (test -e $oldBakFile)
then
rm -rf $oldBakFile
echo "delete full sql $oldBakFile" >> $LogFile
else
echo "$oldBakFile not exist!" >> $LogFile
fi
else
echo "Warning:There is no backup today!!" >> $LogFile
fi
Last=date +"%Y年%m月%d日 %H:%M:%S"
echo 开始:$Begin 结束:$Last succ >> $LogFile
0 23 0 /bin/sh /home/backup/Mysql-FullyBak.sh > /home/backup/cronlog.txt 2>&1
45 23 0 /bin/sh /home/backup/rmBak.sh > /home/backup/cronlog.txt 2>&1
30 23 * /bin/sh /home/backup/scpBak.sh > /home/backup/cronlog.txt 2>&1
#! /bin/bash
username=root
ps='TH'
mysql_data="/home/mysql_backup/data"/lvshan.sql
password=echo $ps|base64 -d
mysql_zip="/home/mysql_backup/data"/lvshan_zip.zip
mysql_back="/home/mysqlbackup/data"/lvshandata +%Y_%m_%d
.zip
/usr/bin/mysqldump --opt -u$username -p$password -hlocalhost lvshan > $mysql_data
/bin/zip $mysql_zip $mysql_data
/bin/rm $mysql_data
openssl enc -k 备份加密密码 -aes-128-ecb -e -in $mysql_zip -out $mysql_back
/bin/rm $mysql_zip
scp -P 6008 $mysql_back root@ip:/home/mysql_backup_lvshan_ip
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站栏目:mysql数据库备份脚本-创新互联
浏览路径:http://azwzsj.com/article/doiioe.html