gp_dump是GP并行备份的备份工具,在运行gp_dump的时候master与所有的segment节点都开始备份,数据文件都是放在各种的节点服务器上,消耗的时间和数据量最大的、消耗时间最长的节点有关,这里就不全部介绍gp_dump所有的参数,可以自行gp_dump --help查看。下面只介绍下面实验用到的参数。
-h GPmaster主机名
-p GPmaster端口
-U 用户名
-c 备份包含数据定义删除语句
-d 库名
--gp-d 备份的数据目录
--gp-r 备份report目录
测试:
一、创建测试数据
1、create table a as select id from generate_series(1,10000) id distributed by (id)
-- 创建10000条数据
2、创建几个function对象
二、备份
[root@gp-master ~]# gp_dump -h 172.30.248.242 -p 5432 -U gpadmin -d recover --gp-d /disk/backup/ --gp-r /disk/backup/
.....
20161102:18:35:27|gp_dump-[FATAL]:-could not start Greenplum Database backup: ERROR: could not create backup directory "/disk/backup/": Permission denied
20161102:18:35:27|gp_dump-[FATAL]:-could not start Greenplum Database backup: ERROR: could not create backup directory "/disk/backup/": Permission denied
20161102:18:35:27|gp_dump-[FATAL]:-could not start Greenplum Database backup: ERROR: could not create backup directory "/disk/backup/": Permission denied
20161102:18:35:27|gp_dump-[FATAL]:-could not start Greenplum Database backup: ERROR: could not create backup directory "/disk/backup/": Permission denied
20161102:18:35:28|gp_dump-[FATAL]:-could not start Greenplum Database backup: ERROR: could not create backup directory "/disk/backup/": Permission denied
20161102:18:35:28|gp_dump-[FATAL]:-could not start Greenplum Database backup: ERROR: could not create backup directory "/disk/backup/": Permission denied
....
节点上没有目录权限
这个时候需要kill掉这个gp_dump进程
[root@gp-master backup]# ps -ef | grep gp_dump
gpadmin 27296 26783 0 18:35 pts/0 00:00:00 gp_dump -h 172.30.248.242 -p 5432 -d recover --gp-d /disk/backup/ --gp-r /disk/backup/
root 27386 27334 0 18:37 pts/1 00:00:00 grep gp_dump
[root@gp-master backup]# kill -9 27296
创建目录并给予权限
[root@gp-master ~]# gpssh -f /tmp/segment_key -e 'mkdir -p /disk/backup'
[gp-segment4] mkdir -p /disk/backup
[gp-segment5] mkdir -p /disk/backup
[gp-segment1] mkdir -p /disk/backup
[gp-segment2] mkdir -p /disk/backup
[gp-segment3] mkdir -p /disk/backup
[root@gp-master ~]# gpssh -f /tmp/segment_key -e 'chown -R gpadmin:gpadmin /disk/backup'
[gp-segment4] chown -R gpadmin:gpadmin /disk/backup
[gp-segment1] chown -R gpadmin:gpadmin /disk/backup
[gp-segment5] chown -R gpadmin:gpadmin /disk/backup
[gp-segment2] chown -R gpadmin:gpadmin /disk/backup
[gp-segment3] chown -R gpadmin:gpadmin /disk/backup
再次执行gp_dump备份
[root@gp-master ~]# gp_dump -h 172.30.248.242 -p 5432 -U gpadmin -d recover --gp-d /disk/backup/ --gp-r /disk/backup/
......
Greenplum Database Backup Report
Timestamp Key: 20161102184312
gp_dump Command Line: -h 172.30.248.242 -p 5432 -U gpadmin -d recover --gp-d /disk/backup/ --gp-r /disk/backup/
Pass through Command Line Options: -d
Compression Program: None
Backup Type: Full
Individual Results
segment 7 (dbid 9) Host gp-segment4 Port 40001 Database recover BackupFile /disk/backup/gp_dump_0_9_20161102184609 : Succeeded
segment 6 (dbid 8) Host gp-segment4 Port 40000 Database recover BackupFile /disk/backup/gp_dump_0_8_20161102184609 : Succeeded
segment 5 (dbid 7) Host gp-segment3 Port 40001 Database recover BackupFile /disk/backup/gp_dump_0_7_20161102184609 : Succeeded
segment 4 (dbid 6) Host gp-segment3 Port 40000 Database recover BackupFile /disk/backup/gp_dump_0_6_20161102184609 : Succeeded
segment 3 (dbid 5) Host gp-segment2 Port 40001 Database recover BackupFile /disk/backup/gp_dump_0_5_20161102184609 : Succeeded
segment 2 (dbid 4) Host gp-segment2 Port 40000 Database recover BackupFile /disk/backup/gp_dump_0_4_20161102184609 : Succeeded
segment 1 (dbid 3) Host gp-segment1 Port 40001 Database recover BackupFile /disk/backup/gp_dump_0_3_20161102184609 : Succeeded
segment 0 (dbid 2) Host gp-segment1 Port 40000 Database recover BackupFile /disk/backup/gp_dump_0_2_20161102184609 : Succeeded
Master (dbid 1) Host gp-master Port 5432 Database recover BackupFile /disk/backup/gp_dump_1_1_20161102184609 : Succeeded
Master (dbid 1) Host gp-master Port 5432 Database recover BackupFile /disk/backup/gp_dump_1_1_20161102184609 _post_data: Succeeded
gp_dump utility finished successfully.
到segment上看下备份文件
[root@gp-segment4 backup]# ls
gp_dump_0_8_20161102184609 gp_dump_0_9_20161102184609 gp_dump_status_0_8_20161102184609 gp_dump_status_0_9_20161102184609
注:segment上的备份文件格式是gp_dump_0_dbid_timestamp,master上的备份文件格式是gp_dump_1_dbid_timestamp,
这个timestamp在恢复的时候会用到
三、删除数据并恢复
删除数据
truncate table a;
恢复:
[root@gp-master ~]# gp_restore -h 172.30.248.242 -U gpadmin -d recover --gp-d /disk/backup/ --gp-r /disk/backup/ --gp-k=20161102184609
Greenplum Database Restore Report
Timestamp Key: 20161102184609
gp_restore Command Line: -h 172.30.248.242 -U gpadmin -d recover --gp-d /disk/backup/ --gp-r /disk/backup/ --gp-k=20161102184609
Pass through Command Line Options: None
Compression Program: None
Individual Results
Restore of database "recover" on Master database: Failed with error:
{ERROR: function "cdm_account" already exists with same argument types
20161102:19:17:41|gp_restore_agent-[ERROR]:-psql finished abnormally with return code 3.
20161102:19:17:41|gp_restore_agent-[ERROR]:-Finished with errors
}
报错,函数cdm_account已经存在,因为我们只删除了表数据,test库中其他对象没有删除,如果备份的时候带-c参数,备份数据时包含数据定义的删除语句,所以先恢复到别的库
[root@gp-master ~]# gp_restore -h 172.30.248.242 -U gpadmin -d test --gp-d /disk/backup/ --gp-r /disk/backup/ --gp-k=20161102184609
...
gp_restore utility finished successfully.
数据和函数对象都恢复成功
注:在恢复的时候,GP的segment必须与备份的时候一致
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29989552/viewspace-2127566/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29989552/viewspace-2127566/