xtrabackup自动备份脚本

[root@localhost backup]# cat full_backup.sh
#!/bin/bash
DATABASE=test
BACKUP_PATH=/data/backup/$(date +%F)
BACKUP_XTRA_FILE=$BACKUP_PATH/$DATABASE_$(date +%F).tar.gz
BACKUP_LOG=/data/backup/backup.log
CNF=/etc/my.cnf
OLD_PATH=$BACKUP_PATH/$DATABASE_$(date +%F --date='7 days ago')


if [ ! -d $BACKUP_PATH ]
    then
    mkdir -p $BACKUP_PATH
fi


if [ -d $OLD_PATH ]
    then
        rm -rf $OLD_PATH >> $BACKUP_LOG 2>&1
        echo "delete the old dir $(date +%F --date='7 days ago')" > $BACKUP_LOG
fi




cp $CNF $BACKUP_PATH/my.cnf.$(date +%F)


/usr/local/xtrabackup/bin/innobackupex --defaults-file=$CNF --host=localhost --user=root --password=PASSWORD --slave-info --stream=tar $BACKUP_PATH 2> $BACKUP_LOG | gzip > $BACKUP_XTRA_FILE




echo "################################################################" >> $BACKUP_LOG

你可能感兴趣的:(『,数据库知识,』)