[[email protected] ~]# cd /usr/local/src
[[email protected] src]# tar zxvf percona-xtrabackup-2.4.4-Linux-x86_64.tar.gz -C /usr/local
[[email protected] src]# cd /usr/local
[[email protected] local]# mv percona-xtrabackup-2.4.4-Linux-x86_64/ xtrabackup
[[email protected] local]# chown mysql -R xtrabackup/
[[email protected] ~]# su - mysql
[[email protected] ~]$ vi .bash_profile
PATH=$PATH:/usr/local/xtrabackup/bin
[[email protected] ~]$ source .bash_profile
[[email protected] ~]# mkdir -p /usr/local/mysql/backup
[[email protected] ~]# chown -R mysql /usr/local/mysql/backup
[[email protected] ~]# su - mysql
[[email protected] ~]$ vi full_backup.sh
#!/bin/bash
user='root'
passwd='abcd.1234'
my_config='/etc/my.cnf'
backup_dir='/usr/local/mysql/backup'
if [ -f ~/.bash_profile ];
then
. ~/.bash_profile
fi
innobackupex --defaults-file=$my_config --user=$user --password=$passwd $backup_dir
[[email protected] ~]$ chmod a+x full_backup.sh
[[email protected] ~]$ ./full_backup.sh
[[email protected] ~]$ cd /usr/local/mysql/backup/
[[email protected] backup]$ ll
[[email protected] backup]$ cd 2018-02-07_15-31-40/
[[email protected] 2018-02-07_15-31-40]$ ll
[[email protected] ~]$ vi incr_backup.sh
#!/bin/bash
user='root'
passwd='abcd.1234'
my_config='/etc/my.cnf'
backup_dir='/usr/local/mysql/backup'
last_day=$(date -d "1 days ago" +%Y-%m-%d)
filename=$(find $backup_dir -name "$last_day*" -print|awk -F / '{print $NF}')
if [ -f ~/.bash_profile ];
then
. ~/.bash_profile
fi
innobackupex --defaults-file=$my_config --user=$user --password=$passwd --incremental --incremental-basedir=$backup_dir/$filename $backup_dir
[[email protected] ~]$ chmod a+x incr_backup.sh
[[email protected] ~]$ crontab -e
00 3 * * 0 /home/mysql/full_backup.sh>/usr/local/mysql/backup/full_backup.log 2>&1
00 3 * * 1-6 /home/mysql/incr_backup.sh>/usr/local/mysql/backup/incr_backup.log 2>&1
[[email protected] ~]$ crontab -l
00 3 * * 0 /home/mysql/full_backup.sh>/usr/local/mysql/backup/full_backup.log 2>&1
00 3 * * 1-6 /home/mysql/incr_backup.sh>/usr/local/mysql/backup/incr_backup.log 2>&1
原文地址:http://blog.51cto.com/13598811/2069857