Xtrabackup one-click automatic backup script version V2 [original]
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
.