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

Xtrabackup one-click automatic backup script version V2 [original]

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

backup file path backdir=/ASSET.innobackupexmysql is used to back up users user= username mysql user password pass= Password-output information saving path logfile=/var/www/html/index.html

[root@localhost /home]# cat /home/innobackupex.v2.sh #!/ bin/bashbackdir=/ASSET.innobackupexuser=usernamepass=yourpasswordlogfile=/var/www/html/files/index.htmlweek=`date +%u`mkdir $backdir >> /dev/null 2>&1if [ ! -f /globalback ]then cat /dev/null > $logfile innobackupex --user=$user -password=$pass $backdir stat=`echo $?` ls $backdir | tail -n 1 > /globalback basedir=`cat /globalback` last=`ls $backdir | tail -n 1` echo "

" date >> $logfile if [ $stat -ne 0 ] then echo "Backup failed! " >> $logfile exit fi echo "

It is detected that no global backup has been done before. Make a complete backup once!

" >> $logfile echo -n "Binary log file used in this global backup, ending position information: " >> $logfile cat $backdir/$basedir/xtrabackup_binlog_info >> $logfile echo -n "

Binary log file path " >> $logfile grep "^log-bin" /etc/my.cnf >> $logfile echo "

The lsn information of this database backup file is as follows:

Start position: " >> $logfile grep from_lsn $backdir/$last/xtrabackup_checkpoints >> $logfile echo "

End position: " >> $logfile grep to_lsn $backdir/$last/xtrabackup_checkpoints >> $logfile echo "

Size and path of backup file " >> $logfile du -sh $backdir/$last/ >> $logfile echo "

" >> $logfile exitfiif [ $week -eq 5 ]then innobackupex --user=$user -password=$pass $backdir stat=`echo $?` incre=`ls $backdir | tail -n 1` if [ $stat -ne 0 ] then echo "

" >> $logfile date >> $logfile echo "

Backup failed! " >> $logfile exit fi ls $backdir | tail -n 1 > /globalback basedir=`cat /globalback` echo "

↓↓↓↓↓↓↓↓↓↓↓ Global backup split line <$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$<$

" >> $logfile date >> $logfile echo "

global backup

" >> $logfile echo "Location of data backup $backdir/$basedir

" >> $logfile echo -n "Binary log file used in this global backup, ending position information: " >> $logfile cat $backdir/$basedir/xtrabackup_binlog_info >> $logfile echo -n "

Binary log file path " >> $logfile grep "^log-bin" /etc/my.cnf >> $logfile echo "

The lsn information of this database backup file is as follows:

Start position: " >> $logfile grep from_lsn $backdir/$basedir/xtrabackup_checkpoints >> $logfile echo "

End position: " >> $logfile grep to_lsn $backdir/$basedir/xtrabackup_checkpoints >> $logfile echo "

Size and path of backup file " >> $logfile du -sh $backdir/$basedir >> $logfile echo "

" >> $logfileelse basedir=`cat /globalback` last=`ls $backdir | tail -n 1` innobackupex --user=$user -password=$pass --incremental $backdir --incremental-basedir=$backdir/$last stat=`echo $?` incre=`ls $backdir | tail -n 1` echo "

" >> $logfile date >> $logfile if [ $stat -ne 0 ] then echo "Backup failed! " >> $logfile exit fi echo "

incremental backup

" >> $logfile echo "basedir is $backdir/$basedir

" >> $logfile echo "Last backup was $backdir/$last

" >> $logfile echo "This backup is $backdir/$incre

" >> $logfile echo -n "Binary log file used by last global backup, as of" >> $logfile cat $backdir/$basedir/xtrabackup_binlog_info >> $logfile echo -n "

Binary log file used in this incremental backup, with cut-off information: " >> $logfile cat $backdir/$incre/xtrabackup_binlog_info >> $logfile echo -n "

Binary log file path " >> $logfile grep "^log-bin" /etc/my.cnf >> $logfile echo "

The lsn information of this incremental database backup file is as follows:

Start position: " >> $logfile grep from_lsn $backdir/$incre/xtrabackup_checkpoints >> $logfile echo "

End position: " >> $logfile grep to_lsn $backdir/$incre/xtrabackup_checkpoints >> $logfile echo "

incremental backup file size, path " >> $logfile du -sh $backdir/$incre >> $logfile echo "

" >> $logfilefi

.

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

Network Security

Wechat

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

12
Report