Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql database backup script

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

#! / 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 database login account-p database password-- all-databases > $DumpFile

/ bin/tar jvcf $BZDumpFile $DumpFile

/ bin/rm $DumpFile

Openssl enc-k backup encrypted password-aes-128-ecb-e-in $BZDumpFile- out $BZDumpFile-aes

#-d decryption

/ bin/rm $BZDumpFile

Last=date + "Y% m / d% H:%M:%S"

Echo "" > > $LogFile

Echo "- fullybak-" > > $LogFile

Echo "$BZDumpFile-aes copying" > > $LogFile

Echo start: $Begin end: $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 start: $Begin end: $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" > > $LogFileelse echo "$oldBakDir1 not exist!" > > $LogFilefiif (test-e $oldBakDir2) then rm-rf $oldBakDir2 echo "delete increased sql $oldBakDir2" > > $LogFileelse echo "$oldBakDir2 not exist!" > $LogFilefiif (test-e $oldBakDir3) then rm-rf $oldBakDir3 echo "delete increased sql $oldBakDir3" > > $LogFileelse echo "$oldBakDir3 not exist!" > > $LogFilefiif (test-e $oldBakDir4) then rm-rf $oldBakDir4 echo "oldBakDir4 echo $delete increased sql" > > $delete increased sql Echo "$oldBakDir4 not exist!" > > $LogFilefiif (test-e $oldBakDir5) then rm-rf $oldBakDir5 echo "delete increased sql $oldBakDir5" > > $LogFileelse echo "$oldBakDir5 not exist!" > > $LogFilefiif (test-e $oldBakDir6) then rm-rf $oldBakDir6 echo "delete increased sql $oldBakDir6" > > $LogFileelse echo "$oldBakDir6 not exist!" > $LogFilefiif (test-e $oldBakFile) then rm-rf $oldBakFile echo "delete full sql $oldBakFile" > $LogFileelse echo "$oldBakFile not exist!" > $LogFilefi

Else

Echo "Warning:There is no backup todaylights!" > > $LogFile

Fi

Last=date + "Y% m / d% H:%M:%S"

Echo start: $Begin end: $Last succ > > $LogFile

0 230 / 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 backup encrypted password-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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report