部署xtrabckup备份_附带shell增量脚本
2014-11-07 12:15
507 查看
需要的安装包:
percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm
注意,该安装包不适合rhel4或CentOS4的操作系统,安装升级perl系统lib库会引起OS崩溃
操作系统环境介绍:
innobackupex innobackupex-1.5.1 innochecksum
表示安装正确
#cd /database/studyfun
# mkdir backup
创建脚本
#touch xtrabackup.sh
需要根据数据库具体配置修改如下
# chmod +x xtrabackup.sh
创建备份用户
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backupuser'@'localhost' identified by '123456';
FLUSH PRIVILEGES;
加入crontab定时任务
# crontab -l
10 02 * * * /database/studyfun/xtrabackup.sh
附
xtrbackup.sh脚本
报错1安装报错
[root@439607-db1-crov local]# rpm -ivh percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm
warning: percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID cd2efd2a
error: Failed dependencies:
perl(DBD::mysql) is needed by percona-xtrabackup-2.1.4-656.rhel5.x86_64
出现上述报错,需要执行“yum install perl-DBD-MySQL”
报错2
日志报错Can't connect to local MySQL server through socket '/tmp/mysql.sock'
备份脚本xtrabackup.sh添加socket="/tmp/mysql_umc.sock",如果还报错,是因为脚本拷贝过程中产生了问题,从正确部署的机器上拷贝即可
报错3, 执行备份脚本报错line 35: break: only meaningful in a `for', `while', or `until' loop
原因:脚本错误,请重新粘贴上述提供的脚本,并注意排版,避免乱行
percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm
注意,该安装包不适合rhel4或CentOS4的操作系统,安装升级perl系统lib库会引起OS崩溃
操作系统环境介绍:
[root@im-web local]# lsb_release -a LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch Distributor ID: CentOS Description: CentOS release 5.2 (Final) Release: 5.2 Codename: Final [root@sf1 ~]# mv percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm /usr/local/ [root@sf1 ~]# cd /usr/local/ 安装 [root@sf1 local]# rpm -ivh percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm warning: percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID cd2efd2a Preparing... ########################################### [100%] 1:percona-xtrabackup ########################################### [100%][root@sf1 local]# inno
innobackupex innobackupex-1.5.1 innochecksum
表示安装正确
#cd /database/studyfun
# mkdir backup
创建脚本
#touch xtrabackup.sh
需要根据数据库具体配置修改如下
backdir=/database/xmobile/backup redun=/database/xmobile/redundency file_cnf=/etc/my_xmobile.cnf user_name=backupuser password="123456" socket="/tmp/mysql_xmobile.sock" if [ ! -d "/database/xmobile/redundency" ]; then mkdir -p /database/xmobile/redundency fi [root@sf1 studyfun]# ll total 20 drwxr-xr-x 2 root root 4096 Oct 8 16:44 backup drwxr-xr-x 2 mysql mysql 4096 Oct 8 15:53 binlog drwxr-xr-x 5 mysql mysql 4096 Oct 8 15:53 data drwxr-xr-x 2 mysql mysql 4096 Oct 8 15:53 relaylog -rwxr-xr-x 1 root root 3528 Oct 8 16:45 xtrabackup.sh给脚本赋执行权限
# chmod +x xtrabackup.sh
创建备份用户
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backupuser'@'localhost' identified by '123456';
FLUSH PRIVILEGES;
加入crontab定时任务
# crontab -l
10 02 * * * /database/studyfun/xtrabackup.sh
附
xtrbackup.sh脚本
[root@sf1 data]# cat /database/studyfun/xtrabackup.sh #!/bin/bash BEGINTIME=`date +"%Y-%m-%d %H:%M:%S"` format_time=`date +"%Y-%m-%d_%H:%M:%S"` week=`date +%Y-%m-%d` backupbin=/usr/bin backdir=/database/studyfun/backup redun=/database/studyfun/backup/redundency file_cnf=/etc/my_studyfun.cnf user_name=backupuser password="123456" socket="/tmp/mysql_studyfun.sock" out_log=$backdir/xtrabackup_log_$format_time time_cost=$backdir/xtrabackup_time.txt if [ ! -d "/database/studyfun/backup/redundency" ]; then mkdir -p /database/studyfun/backup/redundency fi if [ -d "$backdir/incr5" ];then tar -czvf ${redun}\/redundency_${week}.gz $backdir >/dev/null 2>&1 rm -rf $backdir mkdir $backdir # del backup DEL_UNTIL_DATE=`date --date='14 day ago' +%Y-%m-%d` /bin/rm -f /${redun}/*${DEL_UNTIL_DATE}.gz >/dev/null 2>&1 fi #full if [ ! -d "$backdir/full" ];then echo "#####start full backup at $BEGINTIME to directory full" >>$time_cost $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info $backdir/full 1> $out_log 2>&1 break; elif [ ! -d "$backdir/incr0" ];then echo "#####start 0 incremental backup at $BEGINTIME to directory incr0" >>$time_cost $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info --incremental --incremental-basedir=$backdir/full $backdir/incr0 1> $out_log 2>&1 break; elif [ ! -d "$backdir/incr1" ];then echo "#####start 1 incremental backup at $BEGINTIME to directory incr1" >>$time_cost $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info --incremental --incremental-basedir=$backdir/incr0 $backdir/incr1 1> $out_log 2>&1 break; elif [ ! -d "$backdir/incr2" ];then echo "#####start 2 incremental backup at $BEGINTIME to directory incr2" >>$time_cost $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info --incremental --incremental-basedir=$backdir/incr1 $backdir/incr2 1> $out_log 2>&1 break; elif [ ! -d "$backdir/incr3" ];then echo "#####start 3 incremental backup at $BEGINTIME to directory incr3" >>$time_cost $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket -- slave-info --incremental --incremental-basedir$backdir/incr2 $backdir/incr3 1> $out_log 2>&1 break; elif [ ! -d "$backdir/incr4" ];then echo "#####start 4 incremental backup at $BEGINTIME to directory incr4" >>$time_cost $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info --incremental --incremental-basedir=$backdir/incr3 $backdir/incr4 1> $out_log 2>&1 break; elif [ ! -d "$backdir/incr5" ];then echo "#####start 5 incremental backup at $BEGINTIME to directory incr5" >>$time_cost $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info --incremental --incremental-basedir=$backdir/incr4 $backdir/incr5 1> $out_log 2>&1 break; fi ENDTIME=`date +"%Y-%m-%d %H:%M:%S"` begin_data=`date -d "$BEGINTIME" +%s` end_data=`date -d "$ENDTIME" +%s` spendtime=`expr $end_data - $begin_data` echo "it takes $spendtime sec for packing the data directory" >>$time_cost------------遇到的问题----
报错1安装报错
[root@439607-db1-crov local]# rpm -ivh percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm
warning: percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID cd2efd2a
error: Failed dependencies:
perl(DBD::mysql) is needed by percona-xtrabackup-2.1.4-656.rhel5.x86_64
出现上述报错,需要执行“yum install perl-DBD-MySQL”
报错2
日志报错Can't connect to local MySQL server through socket '/tmp/mysql.sock'
#cat xtrabackup_log_2014-11-03_02:10:01 InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy and Percona Ireland Ltd 2009-2012. All Rights Reserved. This software is published under the GNU GENERAL PUBLIC LICENSE Version 2, June 1991. 141103 02:10:02 innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/my_umc.cnf;mysql_read_default_group=xtrabackup' as 'backupuser' (using password: YES). ERROR: Failed to connect to MySQL server: DBI connect(';mysql_read_default_file=/etc/my_umc.cnf;mysql_read_default_group=xtrabackup','backupuser',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at /usr/bin/innobackupex line 1384解决:
备份脚本xtrabackup.sh添加socket="/tmp/mysql_umc.sock",如果还报错,是因为脚本拷贝过程中产生了问题,从正确部署的机器上拷贝即可
报错3, 执行备份脚本报错line 35: break: only meaningful in a `for', `while', or `until' loop
原因:脚本错误,请重新粘贴上述提供的脚本,并注意排版,避免乱行
相关文章推荐
- percona xtrabackupd定期做全备,增量备份shell脚本
- percona xtrabackupd定期做全备,增量备份shell脚本
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- Nocatalog 下的RMAN 增量备份 shell脚本
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- Mysql日常备份和增量备份SHELL脚本
- svn服务器端的增量备份脚本(shell)
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- RMAN 增量备份shell脚本
- Nocatalog 下的RMAN 增量备份 shell脚本
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- Nocatalog 下的RMAN 增量备份 shell脚本
- Nocatalog 下的RMAN 增量备份 shell脚本
- Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
- 用Shell脚本在推出的RAC节点上批量部署32个Oracle11gR2 RAC备份恢复案例场景的方法PART1 推荐
- Nocatalog 下的RMAN 增量备份 shell脚本