|
16 | 16 | void
|
17 | 17 | generate_old_dump(void)
|
18 | 18 | {
|
19 |
| - /* run new pg_dumpall binary */ |
20 |
| - prep_status("Creating catalog dump"); |
| 19 | + int dbnum; |
21 | 20 |
|
22 |
| - /* |
23 |
| - * --binary-upgrade records the width of dropped columns in pg_class, and |
24 |
| - * restores the frozenid's for databases and relations. |
25 |
| - */ |
| 21 | + prep_status("Creating catalog dump\n"); |
| 22 | + |
| 23 | + pg_log(PG_REPORT, OVERWRITE_MESSAGE, "global objects"); |
| 24 | + |
| 25 | + /* run new pg_dumpall binary for globals */ |
26 | 26 | exec_prog(UTILITY_LOG_FILE, NULL, true,
|
27 |
| - "\"%s/pg_dumpall\" %s --schema-only --binary-upgrade %s -f %s", |
| 27 | + "\"%s/pg_dumpall\" %s --schema-only --globals-only --binary-upgrade %s -f %s", |
28 | 28 | new_cluster.bindir, cluster_conn_opts(&old_cluster),
|
29 | 29 | log_opts.verbose ? "--verbose" : "",
|
30 |
| - ALL_DUMP_FILE); |
31 |
| - check_ok(); |
32 |
| -} |
33 |
| - |
34 |
| - |
35 |
| -/* |
36 |
| - * split_old_dump |
37 |
| - * |
38 |
| - * This function splits pg_dumpall output into global values and |
39 |
| - * database creation, and per-db schemas. This allows us to create |
40 |
| - * the support functions between restoring these two parts of the |
41 |
| - * dump. We split on the first "\connect " after a CREATE ROLE |
42 |
| - * username match; this is where the per-db restore starts. |
43 |
| - * |
44 |
| - * We suppress recreation of our own username so we don't generate |
45 |
| - * an error during restore |
46 |
| - */ |
47 |
| -void |
48 |
| -split_old_dump(void) |
49 |
| -{ |
50 |
| - FILE *all_dump, |
51 |
| - *globals_dump, |
52 |
| - *db_dump; |
53 |
| - FILE *current_output; |
54 |
| - char line[LINE_ALLOC]; |
55 |
| - bool start_of_line = true; |
56 |
| - char create_role_str[MAX_STRING]; |
57 |
| - char create_role_str_quote[MAX_STRING]; |
58 |
| - char filename[MAXPGPATH]; |
59 |
| - bool suppressed_username = false; |
60 |
| - |
61 |
| - |
62 |
| - /* |
63 |
| - * Open all files in binary mode to avoid line end translation on Windows, |
64 |
| - * both for input and output. |
65 |
| - */ |
| 30 | + GLOBALS_DUMP_FILE); |
66 | 31 |
|
67 |
| - snprintf(filename, sizeof(filename), "%s", ALL_DUMP_FILE); |
68 |
| - if ((all_dump = fopen(filename, PG_BINARY_R)) == NULL) |
69 |
| - pg_log(PG_FATAL, "Could not open dump file \"%s\": %s\n", filename, getErrorText(errno)); |
70 |
| - snprintf(filename, sizeof(filename), "%s", GLOBALS_DUMP_FILE); |
71 |
| - if ((globals_dump = fopen_priv(filename, PG_BINARY_W)) == NULL) |
72 |
| - pg_log(PG_FATAL, "Could not write to dump file \"%s\": %s\n", filename, getErrorText(errno)); |
73 |
| - snprintf(filename, sizeof(filename), "%s", DB_DUMP_FILE); |
74 |
| - if ((db_dump = fopen_priv(filename, PG_BINARY_W)) == NULL) |
75 |
| - pg_log(PG_FATAL, "Could not write to dump file \"%s\": %s\n", filename, getErrorText(errno)); |
76 |
| - |
77 |
| - current_output = globals_dump; |
78 |
| - |
79 |
| - /* patterns used to prevent our own username from being recreated */ |
80 |
| - snprintf(create_role_str, sizeof(create_role_str), |
81 |
| - "CREATE ROLE %s;", os_info.user); |
82 |
| - snprintf(create_role_str_quote, sizeof(create_role_str_quote), |
83 |
| - "CREATE ROLE %s;", quote_identifier(os_info.user)); |
84 |
| - |
85 |
| - while (fgets(line, sizeof(line), all_dump) != NULL) |
| 32 | + /* create per-db dump files */ |
| 33 | + for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) |
86 | 34 | {
|
87 |
| - /* switch to db_dump file output? */ |
88 |
| - if (current_output == globals_dump && start_of_line && |
89 |
| - suppressed_username && |
90 |
| - strncmp(line, "\\connect ", strlen("\\connect ")) == 0) |
91 |
| - current_output = db_dump; |
| 35 | + char file_name[MAXPGPATH]; |
| 36 | + DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; |
92 | 37 |
|
93 |
| - /* output unless we are recreating our own username */ |
94 |
| - if (current_output != globals_dump || !start_of_line || |
95 |
| - (strncmp(line, create_role_str, strlen(create_role_str)) != 0 && |
96 |
| - strncmp(line, create_role_str_quote, strlen(create_role_str_quote)) != 0)) |
97 |
| - fputs(line, current_output); |
98 |
| - else |
99 |
| - suppressed_username = true; |
| 38 | + pg_log(PG_REPORT, OVERWRITE_MESSAGE, old_db->db_name); |
| 39 | + snprintf(file_name, sizeof(file_name), DB_DUMP_FILE_MASK, old_db->db_oid); |
100 | 40 |
|
101 |
| - if (strlen(line) > 0 && line[strlen(line) - 1] == '\n') |
102 |
| - start_of_line = true; |
103 |
| - else |
104 |
| - start_of_line = false; |
| 41 | + exec_prog(RESTORE_LOG_FILE, NULL, true, |
| 42 | + "\"%s/pg_dump\" %s --schema-only --binary-upgrade --format=custom %s --file=\"%s\" \"%s\"", |
| 43 | + new_cluster.bindir, cluster_conn_opts(&old_cluster), |
| 44 | + log_opts.verbose ? "--verbose" : "", file_name, old_db->db_name); |
105 | 45 | }
|
106 | 46 |
|
107 |
| - fclose(all_dump); |
108 |
| - fclose(globals_dump); |
109 |
| - fclose(db_dump); |
| 47 | + end_progress_output(); |
| 48 | + check_ok(); |
110 | 49 | }
|
0 commit comments