在某些时候需要恢复数据,对于压缩(pg_dump -Fc )的备份文件,如果不确定里面的内容可以通过以下方法确认。
查看备份文件信息和列表
这里有个 francs.dmp 备份文件,如果查看这个备份文件的信息和内容,可以这么做。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
[pg93@redhatB tf]$ pg_restore -l francs.dmp ; ; Archive created at Thu Dec 26 15:48:43 2013 ; dbname: francs ; TOC Entries: 178 ; Compression: -1 ; Dump Version: 1.12-0 ; Format: CUSTOM ; Integer: 4 bytes ; Offset: 8 bytes ; Dumped from database version: 9.3.0 ; Dumped by pg_dump version: 9.3.0 ; ; ; Selected TOC Entries: ; 3074; 1262 16390 DATABASE - francs postgres 6; 2615 16395 SCHEMA - fracns francs 8; 2615 16391 SCHEMA - francs francs 3075; 0 0 ACL - francs francs 7; 2615 2200 SCHEMA - public postgres 3076; 0 0 COMMENT - SCHEMA public postgres 3077; 0 0 ACL - public postgres 701; 2612 16399 PROCEDURAL LANGUAGE - plperlu postgres 216; 3079 12616 EXTENSION - plpgsql 3078; 0 0 COMMENT - EXTENSION plpgsql 217; 3079 16400 EXTENSION - postgres_fdw 3079; 0 0 COMMENT - EXTENSION postgres_fdw 218; 1255 16705 FUNCTION francs dummy() francs 233; 1255 16404 FUNCTION francs func_create_daily_table(character varying, integer) francs 234; 1255 16405 FUNCTION francs multiply(integer, integer) francs 235; 1255 16406 FUNCTION francs my_func() francs 236; 1255 16407 FUNCTION public fun_log_drop_command() postgres 1672; 1417 16408 SERVER - srv_source_db postgres 3080; 0 0 ACL - srv_source_db postgres 3081; 0 0 USER MAPPING - USER MAPPING francs SERVER srv_source_db postgres 215; 1259 24860 TABLE francs 3082; 0 0 ACL francs New_Table francs 172; 1259 16410 TABLE francs 3083; 0 0 ACL francs foo francs 173; 1259 16413 FOREIGN TABLE francs 3084; 0 0 ACL francs ft_test_1 francs 174; 1259 16416 TABLE francs 3085; 0 0 ACL francs test_1 francs 175; 1259 16419 TABLE francs 3086; 0 0 ACL francs test_1_20130725 francs 176; 1259 16422 TABLE francs 3087; 0 0 ACL francs test_1_20130726 francs 177; 1259 16425 TABLE francs 3088; 0 0 ACL francs test_2 francs 178; 1259 16428 TABLE francs 3089; 0 0 ACL francs test_3 francs 179; 1259 16431 TABLE francs 3090; 0 0 ACL francs test_4 francs 214; 1259 16706 TABLE francs 3091; 0 0 ACL francs test_5 francs 180; 1259 16437 TABLE francs 3092; 0 0 ACL francs test_6 francs 213; 1259 16668 TABLE francs 3093; 0 0 ACL francs test_archive francs 181; 1259 16441 TABLE francs 3094; 0 0 ACL francs test_array francs 212; 1259 16665 TABLE francs 3095; 0 0 ACL francs test_big francs 182; 1259 16447 TABLE francs 3096; 0 0 ACL francs test_cache francs 183; 1259 16453 TABLE francs 3097; 0 0 ACL francs test_con francs 184; 1259 16457 TABLE francs 3098; 0 0 ACL francs test_full francs 185; 1259 16460 TABLE francs 3099; 0 0 ACL francs test_full_20130625 francs 186; 1259 16463 TABLE francs 3100; 0 0 ACL francs test_full_20130626 francs 187; 1259 16466 TABLE francs 3101; 0 0 ACL francs test_full_20130627 francs 188; 1259 16469 TABLE francs 3102; 0 0 ACL francs test_full_20130628 francs 189; 1259 16472 TABLE francs 3103; 0 0 ACL francs test_full_20130629 francs 190; 1259 16475 TABLE francs 3104; 0 0 ACL francs test_full_20130630 francs 191; 1259 16478 TABLE francs 3105; 0 0 ACL francs test_full_20130701 francs 192; 1259 16481 TABLE francs 3106; 0 0 ACL francs test_full_20130702 francs 193; 1259 16484 TABLE francs 3107; 0 0 ACL francs test_full_20130703 francs 194; 1259 16487 TABLE francs 3108; 0 0 ACL francs test_full_20130704 francs 195; 1259 16490 TABLE francs 3109; 0 0 ACL francs test_full_20130705 francs 196; 1259 16496 TABLE francs 3110; 0 0 ACL francs test_json1 francs 197; 1259 16503 SEQUENCE francs test_json1_id_seq francs 3111; 0 0 SEQUENCE OWNED BY francs test_json1_id_seq francs 198; 1259 16505 TABLE francs 3112; 0 0 ACL francs test_lock francs 199; 1259 16514 TABLE francs 3113; 0 0 ACL francs test_notice francs 200; 1259 16517 TABLE francs 3114; 0 0 ACL francs test_notice2 francs 201; 1259 16520 SEQUENCE francs test_notice2_id_seq francs 3115; 0 0 SEQUENCE OWNED BY francs test_notice2_id_seq francs 202; 1259 16522 SEQUENCE francs test_notice_id_seq francs 3116; 0 0 SEQUENCE OWNED BY francs test_notice_id_seq francs 211; 1259 16662 TABLE francs 3117; 0 0 ACL francs test_num francs 203; 1259 16524 TABLE francs 3118; 0 0 ACL francs test_pri francs 204; 1259 16527 TABLE francs 3119; 0 0 ACL francs test_state francs 205; 1259 16531 TABLE francs 3120; 0 0 ACL francs test_sub francs 206; 1259 16534 TABLE francs 3121; 0 0 ACL francs test_trigger_bk francs 207; 1259 16537 TABLE francs 3122; 0 0 ACL francs test_view1 francs 208; 1259 16540 TABLE francs 3123; 0 0 ACL francs test_xlog francs 209; 1259 16543 VIEW francs view1_test francs 3124; 0 0 ACL francs view1_test francs 210; 1259 16547 TABLE public 3125; 0 0 ACL public tbl_ddl_drop_log postgres 2874; 2604 16553 DEFAULT francs id francs 2875; 2604 16554 DEFAULT francs id francs 2876; 2604 16555 DEFAULT francs id francs 3069; 0 24860 TABLE DATA 3028; 0 16410 TABLE DATA 3029; 0 16416 TABLE DATA 3030; 0 16419 TABLE DATA 3031; 0 16422 TABLE DATA 3032; 0 16425 TABLE DATA 3033; 0 16428 TABLE DATA 3034; 0 16431 TABLE DATA 3068; 0 16706 TABLE DATA 3035; 0 16437 TABLE DATA 3067; 0 16668 TABLE DATA 3036; 0 16441 TABLE DATA 3066; 0 16665 TABLE DATA 3037; 0 16447 TABLE DATA 3038; 0 16453 TABLE DATA 3039; 0 16457 TABLE DATA 3040; 0 16460 TABLE DATA 3041; 0 16463 TABLE DATA 3042; 0 16466 TABLE DATA 3043; 0 16469 TABLE DATA 3044; 0 16472 TABLE DATA 3045; 0 16475 TABLE DATA 3046; 0 16478 TABLE DATA 3047; 0 16481 TABLE DATA 3048; 0 16484 TABLE DATA 3049; 0 16487 TABLE DATA 3050; 0 16490 TABLE DATA 3051; 0 16496 TABLE DATA 3126; 0 0 SEQUENCE SET francs 3053; 0 16505 TABLE DATA 3054; 0 16514 TABLE DATA 3055; 0 16517 TABLE DATA 3127; 0 0 SEQUENCE SET francs 3128; 0 0 SEQUENCE SET francs 3065; 0 16662 TABLE DATA 3058; 0 16524 TABLE DATA 3059; 0 16527 TABLE DATA 3060; 0 16531 TABLE DATA 3061; 0 16534 TABLE DATA 3062; 0 16537 TABLE DATA 3063; 0 16540 TABLE DATA 3064; 0 16547 TABLE DATA 2879; 2606 16607 CONSTRAINT francs test_4_pkey francs 2883; 2606 16609 CONSTRAINT francs test_full_20130625_pkey francs 2885; 2606 16611 CONSTRAINT francs test_full_20130626_pkey francs 2887; 2606 16613 CONSTRAINT francs test_full_20130627_pkey francs 2889; 2606 16615 CONSTRAINT francs test_full_20130628_pkey francs 2891; 2606 16617 CONSTRAINT francs test_full_20130629_pkey francs 2893; 2606 16619 CONSTRAINT francs test_full_20130630_pkey francs 2895; 2606 16621 CONSTRAINT francs test_full_20130701_pkey francs 2897; 2606 16623 CONSTRAINT francs test_full_20130702_pkey francs 2899; 2606 16625 CONSTRAINT francs test_full_20130703_pkey francs 2901; 2606 16627 CONSTRAINT francs test_full_20130704_pkey francs 2903; 2606 16629 CONSTRAINT francs test_full_20130705_pkey francs 2881; 2606 16631 CONSTRAINT francs test_full_pkey francs 2905; 2606 16633 CONSTRAINT francs test_json1_pkey francs 2907; 2606 16635 CONSTRAINT francs test_lock_pkey francs 2911; 2606 16641 CONSTRAINT francs test_notice2_pkey francs 2909; 2606 16639 CONSTRAINT francs test_notice_pkey francs 2913; 2606 16643 CONSTRAINT francs test_pri_pkey francs 2916; 2606 16646 CONSTRAINT francs test_sub_pkey francs 2918; 2606 16648 CONSTRAINT francs test_view1_pkey francs 2914; 1259 16644 INDEX francs uni_test_pri_name francs 3027; 2618 16603 RULE francs rule_foo francs 2870; 3466 16602 EVENT TRIGGER - trg_log_drop_command postgres
|
备注:上面列出了数据库的函数,表,序列等列表,由于 francs.dmp 是压缩过的二进制文件,如果想转换成 sql 文件,应该如何做呢?
转换二进制文件
由于 .dmp 文件是通过 -Fc 压缩的二进制文件,且压缩比很大,如果想查看其详细SQL 内容,可通过以下命令查看,这里仅查看头部 50 行.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
[pg93@redhatB tf]$ pg_restore francs.dmp | head -n 50 -- -- PostgreSQL database dump -- SET statement_timeout = 0; SET lock_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SET check_function_bodies = false; SET client_min_messages = warning; -- -- Name: fracns; Type: SCHEMA; Schema: -; Owner: francs -- CREATE SCHEMA fracns; ALTER SCHEMA fracns OWNER TO francs; -- -- Name: francs; Type: SCHEMA; Schema: -; Owner: francs -- CREATE SCHEMA francs; ALTER SCHEMA francs OWNER TO francs; -- -- Name: plperlu; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres -- CREATE OR REPLACE PROCEDURAL LANGUAGE plperlu; ALTER PROCEDURAL LANGUAGE plperlu OWNER TO postgres; -- -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -- CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; -- -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -- COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
|
备注: pg_dump
备份时有四种格式 p(plain), c(custom), d(directory), t(tar),其中 custom 格式最为灵活,建议使用,关于各参数详见以下文档。
参考
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/238031.html