mysql数据库备份脚本

发布时间:2020-07-30 12:25:26 作者:Man_Docker
来源:网络 阅读:162

#!/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

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

推荐阅读:
  1. MongoDB 数据库备份脚本
  2. 如何用bat脚本+mysqldump进行mysql的数据库备份

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql数据库备份脚本 份脚本 l数据库

上一篇:WebApi特性路由

下一篇:BaseActivity公用界面的使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》