直接上脚本
热备(全备)
#!/bin/bash user='root' passwd='123456' my_config='/etc/my.cnf' #mysql configure log=full-$(date +%Y%m%d-%H%M).log #log file format str=full-$(date +%Y%m%d-%H%M).tar.gz #mysqlbackup file format backup_dir='/var/www/html/manager/data/html/fullmysqlbackup/' #tar file directory echo "Start to backup at $(date +%Y%m%d-%H%M)" if [ ! -d "$backup_dir" ]; then mkdir -p $backup_dir fi innobackupex --user=$user --password=$passwd --defaults-file=$my_config --databases="databases1 databases2" --stream=tar $backup_dir 2>$backup_dir/$log |gzip 1>$backup_dir/$str # backup two databases and compress bakcup if [ $? -eq 0 ];then echo "Backup is finish! at $(date +%Y%m%d-%H%M)" else echo "Backup is Fail! at $(date +%Y%m%d-%H%M)" fi
#Author:V
恢复:(恢复要停掉数据库的哦)
service mysqld stop mv /var/lib/mysql /var/lib/mysqlbackup mkdir -p /var/lib/mysql cd /home/backup tar -izxvf full-20150820-0939.tar.gz -C /home/full cd /home/full innobackupex --user=root --password=123456 --apply-log /home/full innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --copy-back /home/full chown -R mysql.mysql /var/lib/mysql service mysqld start #Changed some file path, please change your. Author:V
自动删除备份:
#!/bin/bash #author:V #Dispaly:auto delete mysql backup. BACKDIR=/home/11/mysqlbackup/ DAYS=3 FILENAME="full*" LOGNAME=/var/log/autodel.log DATA=`date +%Y%m%d` find $BACKDIR -name "$FILENAME" -type f -mtime +$DAYS -exec ls -lh {} ; >> $LOGNAME 2>&1 if [ $? -eq 0 ];then echo "$DATA OK">>$LOGNAME else echo "$DATA FAIL">>$LOGNAME exit 0 fi #Changed some file path, please change your. Author :V