HGDB使用-l和-L选项恢复指定的数据库对象

来源:互联网 发布:网络架构图怎么做 编辑:程序博客网 时间:2024/06/08 08:44
-l 或 --list
列出归档内容,该操作的输出可以用作输入的-L选项。注意如果过滤选项(-n -t)与-l一起
他们将显示列出的项

-L list-file 或 --use-list=list-file
仅恢复那些在list-file中列出的归档元素,按照他们出现的顺序恢复
可以先运行 pg_restore -l命令然后编辑结果作为-L的输入文件

备份
> pg_dump -Fc -d highgo -f highgo.c.dump
还原
> createdb -T template0 testdb1
>  pg_restore -d testdb1 highgo.c.dump 

使用-l查看备份文件中包含的内容并输出到文件中:
> pg_restore -l highgo.c.dump > highgo.c.dump.list
> 查看文件highgo.c.dump.list的内容
;
; Archive created at 2017-09-05 11:07:39
;     dbname: highgo
;     TOC Entries: 13
;     Compression: -1
;     Dump Version: 1.12-0
;     Format: CUSTOM
;     Integer: 4 bytes
;     Offset: 8 bytes
;     Dumped from database version: 9.5.7
;     Dumped by pg_dump version: 9.5.7
;
;
; Selected TOC Entries:
;
2635; 1262 12428 DATABASE - highgo Administrator
2636; 1262 12428 COMMENT - highgo Administrator
9; 2615 2200 SCHEMA - public Administrator
2637; 0 0 COMMENT - SCHEMA public Administrator
2638; 0 0 ACL - public Administrator
1; 3079 12410 EXTENSION - plpgsql 
2639; 0 0 COMMENT - EXTENSION plpgsql 
186; 1259 16384 TABLE public tab1 Administrator
187; 1259 24594 TABLE public test highgo
2629; 0 16384 TABLE DATA public tab1 Administrator
2630; 0 24594 TABLE DATA public test highgo


只需要将不需要恢复的对象使用;注释掉就可以了,然后还原带上此列表
$ createdb -T template0 testdb2

编辑文件highgo.c.dump.list,仅保留如下两行(即仅将test表及其数据恢复到新数据库中):
187; 1259 24594 TABLE public test highgo
2630; 0 24594 TABLE DATA public test highgo

$ pg_restore -L highgo.c.dump.list -d testdb2 highgo.c.dump


C:\Users\Administrator>psql -d testdb2 -U highgo
psql (4.1.1)
PSQL: Release 4.1.1
Connected to:
HighGo Database V4.1 Enterprise Edition Release 4.1.1 - 64-bit Production
输入 "help" 来获取帮助信息.
testdb2=# \dt
             关联列表
 架构模式 | 名称 |  类型  | 拥有者
----------+------+--------+--------
 public   | test | 数据表 | highgo
(1 行记录)

testdb2=# select * from test;
 id
----
  1
  1
(2 行记录)
原创粉丝点击