KingbaseES V8R3备份恢复案例之--单实例环境sys_rman脚本备份案例
作者:互联网
案例说明:
sys_rman是KingbaseES数据库的物理备份工具,支持数据库的全备和增量备份,由于sys_rman工具使用需要配置多个参数,对于一般用户使用不是很方便。为方便用户在KingbaseES V8R3版本,通过sys_rman执行物理备份,系统自带了调用sys_rman的备份脚本,本次文档对脚本的使用进行了详细的描述,帮助用户快速掌握此脚本的使用。
适用版本:
KingbaseES V8R3
一、脚本部署路径(单实例环境)
[kingbase@node101 rman]$ pwd
/opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman
二、查看文件信息
[kingbase@node101 rman]$ ls -lh
total 24K
-rwxr-xr-x 1 kingbase kingbase 5.0K Apr 1 2021 fast_deploy_rman.sh
-rwxr-xr-x 1 kingbase kingbase 3.1K Apr 1 2021 rman_check.sh
-rwxr-xr-x 1 kingbase kingbase 250 Jun 15 13:57 rman.conf
-rwxr-xr-x 1 kingbase kingbase 2.7K Apr 1 2021 rman_full.sh
-rwxr-xr-x 1 kingbase kingbase 2.0K Apr 1 2021 rman_page.sh
Tips:
1) rman_full.sh 用于物理全部
2)rman_page.sh 用于增量备份
3) rman_check.sh 用于备份后的校验和查看
4) rman.conf 用于备份配置
5) fast_deploy_rman.sh 用于建立crontab备份计划
三、数据库归档配置
=注意:sys_rman支持热备,所以数据库必须配置为归档模式。=
四、备份配置
[kingbase@node101 rman]$ cat rman.conf
kdb_home="/opt/Kingbase/ES/V8R3_290/Server/"
kdb_data="/data/kingbase/v8r3_290/data" #数据库存储路径
kdb_user="system"
kdb_pass="123456"
kdb_port="54323"
kdb_host="127.0.0.1"
kdbback_dest="/data/kingbase/backup" #备份文件存储路径
kdbarchive_dest="/data/kingbase/archive" #归档日志存储路径
keep_num="2" #备份保留策略
五、执行数据库备份
1)执行数据库全备
[kingbase@node101 rman]$ sh rman_full.sh
kingbase database rman full backup begin : 2022-06-15 13:57:45
conf file is: /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman.conf
kdb_data: /data/kingbase/v8r3_290/data
kingbase database rman full backup end : 2022-06-15 13:58:20
2)执行增量备份
# 创建增量数据
prod=# create table t1 (id int ,name varchar(10));
CREATE TABLE
prod=# insert into t1 values (generate_series(1,10000),'usr'||generate_series(1,10000));
INSERT 0 10000
prod=# show case_sensitive ;
case_sensitive
----------------
off
(1 row)
prod=# select sys_switch_xlog();
sys_switch_xlog
-----------------
0/C10CAA30
(1 row)
prod=# checkpoint ;
# 执行增量备份
[kingbase@node101 rman]$ sh rman_page.sh
kingbase database rman page backup begin : 2022-06-15 14:16:50
conf file is: /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman.conf
kingbase database rman page backup end : 2022-06-15 14:16:53
3)备份校验和查看
[kingbase@node101 rman]$ sh rman_check.sh
conf file is: /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman.conf
This tool help use to check kingbase database's rman backup file, must execute in local server
2022-06-15 14:17:41 : check begin
kdbback_dest : /data/kingbase/backup is correct
1.check database status:
database is running
2.show kingbase rman backup list:
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RDI9G2 2022-06-15 14:16:53 PAGE 1 / 0 3s 8724kB 0/C4000028 0/C5000078 OK
RDI8K9 2022-06-15 13:58:09 FULL 1 / 0 24s 3341MB 0/BE000028 0/BE000130 OK
3.check every backup ID:
---------------------------------------------------------
check backup ID: RDI9G2
INFO: validate: RDI8K9 backup and archive log files by CRC
INFO: validate: RDI9G2 backup and archive log files by CRC
INFO: backup validation completed successfully
---------------------------------------------------------
check backup ID: RDI8K9
INFO: validate: RDI8K9 backup and archive log files by CRC
INFO: backup validation completed successfully
---------------------------------------------------------
2022-06-15 14:18:00 : check end
4)查看备份信息
[kingbase@node101 backup]$ ls -lh
total 8.0K
-rw-rw-r-- 1 kingbase kingbase 1.2K Jun 15 13:58 backup.log
drwx------ 3 kingbase kingbase 19 Jun 15 13:57 backups
-rw-rw-r-- 1 kingbase kingbase 41 Jun 15 13:57 sys_rman.conf
lrwxrwxrwx 1 kingbase kingbase 31 Jun 15 13:57 wal -> /data/kingbase/v8r3_290/archive
Tips:
1)对于归档日志是在备份目录下建立了链接,执行备份时没有对归档日志执行备份操作。
2)backup.log记录了备份的相关信息。
5)查看备份日志信息
[kingbase@node101 backup]$ tail -1000 backup.log
Wed Jun 15 13:57:45 CST 2022
FULL BACKUP START ...
INFO: validate: RDI8K9 backup and archive log files by CRC
FULL BACKUP SUCCEED!
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RDI8K9 2022-06-15 13:58:09 FULL 1 / 0 24s 3341MB 0/BE000028 0/BE000130 OK
BACKUP RETENTION START ...
INFO: removed min WAL segment "0000000100000000000000BA"
INFO: removed max WAL segment "0000000100000000000000BD"
INFO: purging is finished
RETENTION SUCCEED!
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RDI8K9 2022-06-15 13:58:09 FULL 1 / 0 24s 3341MB 0/BE000028 0/BE000130 OK
Wed Jun 15 14:16:50 CST 2022
PAGE BACKUP START ...
INFO: validate: RDI9G2 backup and archive log files by CRC
PAGE BACKUP SUCCEED!
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RDI9G2 2022-06-15 14:16:53 PAGE 1 / 0 3s 8724kB 0/C4000028 0/C5000078 OK
RDI8K9 2022-06-15 13:58:09 FULL 1 / 0 24s 3341MB 0/BE000028 0/BE000130 OK
Tips:
1)在通过脚本备份完成时,自动对备份进行validate。注意:对于sys_rman的备份,只有做过validate后才是有效的备份。
2)在下次备份前,会根据备份的保留(retention)策略,自动清理不在需要的归档日志。
3)如下所示,backup.log日志中记录的归档日志已被清理。
[kingbase@node101 wal]$ ls -lh
total 129M
-rw------- 1 kingbase kingbase 16M Jun 15 13:58 0000000100000000000000BE
-rw------- 1 kingbase kingbase 321 Jun 15 13:58 0000000100000000000000BE.00000028.backup
-rw------- 1 kingbase kingbase 16M Jun 15 14:03 0000000100000000000000BF
-rw------- 1 kingbase kingbase 16M Jun 15 14:03 0000000100000000000000C0
-rw------- 1 kingbase kingbase 16M Jun 15 14:14 0000000100000000000000C1
-rw------- 1 kingbase kingbase 16M Jun 15 14:14 0000000100000000000000C2
-rw------- 1 kingbase kingbase 16M Jun 15 14:16 0000000100000000000000C3
-rw------- 1 kingbase kingbase 16M Jun 15 14:16 0000000100000000000000C4
-rw------- 1 kingbase kingbase 321 Jun 15 14:16 0000000100000000000000C4.00000028.backup
-rw------- 1 kingbase kingbase 16M Jun 15 14:16 0000000100000000000000C5
六、建立备份的crontab计划任务
=注意:可以根据主机的业务压力情况,建立合理的备份时间,尽量避开业务高峰期。=
# 建立备份计划任务
[kingbase@node101 rman]$ sh fast_deploy_rman.sh
This tool help use to deploy rman backup (rman_full.sh, rman_page.sh) schedual into the crontab
begin deploy, read configuration
conf file is: /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman.conf
1.check database is open archive:
database is already open archive
2.check back_dest and archive_dest :
check /data/kingbase/backup :
back dest is exist
check /data/kingbase/archive :
archive dest is exist
3.check rman_full.sh script:
sucess to execute rman_full.sh
sucess to execute rman_page.sh
4.add backup job:
no crontab for kingbase
no crontab for kingbase
there is no crontab job, add it
5.show current crontab list:
0 23 * * 6 sh /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_full.sh >>/opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_backup.log 2>&1 &
0 23 * * 0-5 sh /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_page.sh >>/opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_backup.log 2>&1 &
end
# 查看kingbase用户计划任务
[kingbase@node101 rman]$ crontab -l
0 23 * * 6 sh /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_full.sh >>/opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_backup.log 2>&1 &
0 23 * * 0-5 sh /opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_page.sh >>/opt/Kingbase/ES/V8R3_290/Server/kb_scripts/kb_backup/rman/rman_backup.log 2>&1 &
七、总结
1)通过系统备份脚本,可以方便用户执行sys_rman的备份。
2)在脚本备份后,自动进行备份的校验。
3)在初次备份后的下一次备份开始,都自动根据备份保留策略清理归档日志。
标签:V8R3,15,备份,kingbase,案例,sh,rman,backup 来源: https://www.cnblogs.com/kingbase/p/16387625.html