21
21
22
22
#include "pgut/pgut-port.h"
23
23
24
- static pgBackup * catalog_read_ini (const char * path );
24
+ static pgBackup * read_backup_from_file (const char * path );
25
25
26
26
#define BOOL_TO_STR (val ) ((val) ? "true" : "false")
27
27
@@ -32,17 +32,16 @@ static int lock_fd = -1;
32
32
* If the lock is held by another one, return 1 immediately.
33
33
*/
34
34
int
35
- catalog_lock (void )
35
+ catalog_lock (bool check_catalog )
36
36
{
37
- int ret ;
38
- char id_path [MAXPGPATH ];
37
+ int ret ;
38
+ char id_path [MAXPGPATH ];
39
39
40
- join_path_components (id_path , backup_path , PG_RMAN_INI_FILE );
40
+ join_path_components (id_path , backup_path , BACKUP_CATALOG_CONF_FILE );
41
41
lock_fd = open (id_path , O_RDWR );
42
42
if (lock_fd == -1 )
43
43
elog (errno == ENOENT ? ERROR : ERROR ,
44
44
"cannot open file \"%s\": %s" , id_path , strerror (errno ));
45
-
46
45
#ifdef __IBMC__
47
46
ret = lockf (lock_fd , LOCK_EX | LOCK_NB , 0 ); /* non-blocking */
48
47
#else
@@ -64,6 +63,19 @@ catalog_lock(void)
64
63
}
65
64
}
66
65
66
+ if (check_catalog )
67
+ {
68
+ uint64 id ;
69
+
70
+ Assert (pgdata );
71
+
72
+ /* Check system-identifier */
73
+ id = get_system_identifier (true);
74
+ if (id != system_identifier )
75
+ elog (ERROR , "Backup directory was initialized for system id = %ld, but target system id = %ld" ,
76
+ system_identifier , id );
77
+ }
78
+
67
79
return 0 ;
68
80
}
69
81
@@ -82,15 +94,15 @@ catalog_unlock(void)
82
94
* If no backup matches, return NULL.
83
95
*/
84
96
pgBackup *
85
- catalog_get_backup (time_t timestamp )
97
+ read_backup (time_t timestamp )
86
98
{
87
99
pgBackup tmp ;
88
- char ini_path [MAXPGPATH ];
100
+ char conf_path [MAXPGPATH ];
89
101
90
102
tmp .start_time = timestamp ;
91
- pgBackupGetPath (& tmp , ini_path , lengthof (ini_path ), BACKUP_INI_FILE );
103
+ pgBackupGetPath (& tmp , conf_path , lengthof (conf_path ), BACKUP_CONF_FILE );
92
104
93
- return catalog_read_ini ( ini_path );
105
+ return read_backup_from_file ( conf_path );
94
106
}
95
107
96
108
static bool
@@ -144,8 +156,8 @@ catalog_get_backup_list(time_t backup_id)
144
156
join_path_components (date_path , backups_path , date_ent -> d_name );
145
157
146
158
/* read backup information from backup.ini */
147
- snprintf (ini_path , MAXPGPATH , "%s/%s" , date_path , BACKUP_INI_FILE );
148
- backup = catalog_read_ini (ini_path );
159
+ snprintf (ini_path , MAXPGPATH , "%s/%s" , date_path , BACKUP_CONF_FILE );
160
+ backup = read_backup_from_file (ini_path );
149
161
150
162
/* ignore corrupted backup */
151
163
if (backup )
@@ -309,7 +321,7 @@ pgBackupWriteIni(pgBackup *backup)
309
321
FILE * fp = NULL ;
310
322
char ini_path [MAXPGPATH ];
311
323
312
- pgBackupGetPath (backup , ini_path , lengthof (ini_path ), BACKUP_INI_FILE );
324
+ pgBackupGetPath (backup , ini_path , lengthof (ini_path ), BACKUP_CONF_FILE );
313
325
fp = fopen (ini_path , "wt" );
314
326
if (fp == NULL )
315
327
elog (ERROR , "cannot open INI file \"%s\": %s" , ini_path ,
@@ -330,7 +342,7 @@ pgBackupWriteIni(pgBackup *backup)
330
342
* - Do not care section.
331
343
*/
332
344
static pgBackup *
333
- catalog_read_ini (const char * path )
345
+ read_backup_from_file (const char * path )
334
346
{
335
347
pgBackup * backup ;
336
348
char * backup_mode = NULL ;
@@ -342,29 +354,29 @@ catalog_read_ini(const char *path)
342
354
343
355
pgut_option options [] =
344
356
{
345
- {'s' , 0 , "backup-mode" , NULL , SOURCE_ENV },
346
- {'u' , 0 , "timelineid" , NULL , SOURCE_ENV },
347
- {'s' , 0 , "start-lsn" , NULL , SOURCE_ENV },
348
- {'s' , 0 , "stop-lsn" , NULL , SOURCE_ENV },
349
- {'t' , 0 , "start-time" , NULL , SOURCE_ENV },
350
- {'t' , 0 , "end-time" , NULL , SOURCE_ENV },
351
- {'U' , 0 , "recovery-xid" , NULL , SOURCE_ENV },
352
- {'t' , 0 , "recovery-time" , NULL , SOURCE_ENV },
353
- {'I' , 0 , "data-bytes" , NULL , SOURCE_ENV },
354
- {'u' , 0 , "block-size" , NULL , SOURCE_ENV },
355
- {'u' , 0 , "xlog-block-size" , NULL , SOURCE_ENV },
356
- {'u' , 0 , "checksum_version" , NULL , SOURCE_ENV },
357
- {'u' , 0 , "stream" , NULL , SOURCE_ENV },
358
- {'s' , 0 , "status" , NULL , SOURCE_ENV },
359
- {'s' , 0 , "parent_backup" , NULL , SOURCE_ENV },
357
+ {'s' , 0 , "backup-mode" , NULL , SOURCE_FILE_STRICT },
358
+ {'u' , 0 , "timelineid" , NULL , SOURCE_FILE_STRICT },
359
+ {'s' , 0 , "start-lsn" , NULL , SOURCE_FILE_STRICT },
360
+ {'s' , 0 , "stop-lsn" , NULL , SOURCE_FILE_STRICT },
361
+ {'t' , 0 , "start-time" , NULL , SOURCE_FILE_STRICT },
362
+ {'t' , 0 , "end-time" , NULL , SOURCE_FILE_STRICT },
363
+ {'U' , 0 , "recovery-xid" , NULL , SOURCE_FILE_STRICT },
364
+ {'t' , 0 , "recovery-time" , NULL , SOURCE_FILE_STRICT },
365
+ {'I' , 0 , "data-bytes" , NULL , SOURCE_FILE_STRICT },
366
+ {'u' , 0 , "block-size" , NULL , SOURCE_FILE_STRICT },
367
+ {'u' , 0 , "xlog-block-size" , NULL , SOURCE_FILE_STRICT },
368
+ {'u' , 0 , "checksum_version" , NULL , SOURCE_FILE_STRICT },
369
+ {'u' , 0 , "stream" , NULL , SOURCE_FILE_STRICT },
370
+ {'s' , 0 , "status" , NULL , SOURCE_FILE_STRICT },
371
+ {'s' , 0 , "parent_backup" , NULL , SOURCE_FILE_STRICT },
360
372
{0 }
361
373
};
362
374
363
375
if (access (path , F_OK ) != 0 )
364
376
return NULL ;
365
377
366
378
backup = pgut_new (pgBackup );
367
- catalog_init_config (backup );
379
+ init_backup (backup );
368
380
369
381
i = 0 ;
370
382
options [i ++ ].var = & backup_mode ;
@@ -516,7 +528,7 @@ pgBackupGetPath(const pgBackup *backup, char *path, size_t len, const char *subd
516
528
}
517
529
518
530
void
519
- catalog_init_config (pgBackup * backup )
531
+ init_backup (pgBackup * backup )
520
532
{
521
533
backup -> backup_mode = BACKUP_MODE_INVALID ;
522
534
backup -> status = BACKUP_STATUS_INVALID ;
0 commit comments