@@ -82,23 +82,9 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
82
82
/* repack the options */
83
83
bool smooth_checkpoint = bkupopt .smooth_checkpoint ;
84
84
85
- /*
86
- * In archive backup mode, check if there is an already validated
87
- * full backup on current timeline.
88
- */
85
+ /* Leave in case od archive mode */
89
86
if (current .backup_mode == BACKUP_MODE_ARCHIVE )
90
- {
91
- pgBackup * prev_backup ;
92
-
93
- prev_backup = catalog_get_last_data_backup (backup_list );
94
- if (prev_backup == NULL )
95
- {
96
- elog (ERROR_SYSTEM , _ ("Full backup detected but it is not "
97
- "validated so archive backup cannot be taken. "
98
- "backup. Validate it and retry." ));
99
- }
100
87
return NULL ;
101
- }
102
88
103
89
elog (INFO , _ ("database backup start" ));
104
90
@@ -113,6 +99,21 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
113
99
*/
114
100
current .tli = get_current_timeline ();
115
101
102
+ /*
103
+ * In incremental backup mode, check if there is an already-validated
104
+ * full backup on current timeline.
105
+ */
106
+ if (current .backup_mode == BACKUP_MODE_INCREMENTAL )
107
+ {
108
+ pgBackup * prev_backup ;
109
+
110
+ prev_backup = catalog_get_last_data_backup (backup_list , current .tli );
111
+ if (prev_backup == NULL )
112
+ elog (ERROR_SYSTEM , _ ("Valid full backup not found for "
113
+ "incremental backup. Either create a full backup "
114
+ "or validate existing one." ));
115
+ }
116
+
116
117
/* notify start of backup to PostgreSQL server */
117
118
time2iso (label , lengthof (label ), current .start_time );
118
119
strncat (label , " with pg_rman" , lengthof (label ));
@@ -167,30 +168,22 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
167
168
* To take incremental backup, the file list of the last completed database
168
169
* backup is needed.
169
170
*/
170
- if (current .backup_mode < BACKUP_MODE_FULL )
171
+ if (current .backup_mode == BACKUP_MODE_INCREMENTAL )
171
172
{
172
173
pgBackup * prev_backup ;
173
174
174
175
/* find last completed database backup */
175
- prev_backup = catalog_get_last_data_backup (backup_list );
176
- if (prev_backup == NULL || prev_backup -> tli != current .tli )
177
- {
178
- elog (ERROR_SYSTEM , _ ("Full backup detected but it is not "
179
- "validated so incremental backup cannot be taken" ));
180
- }
181
- else
182
- {
183
- pgBackupGetPath (prev_backup , prev_file_txt , lengthof (prev_file_txt ),
184
- DATABASE_FILE_LIST );
185
- prev_files = dir_read_file_list (pgdata , prev_file_txt );
176
+ prev_backup = catalog_get_last_data_backup (backup_list , current .tli );
177
+ pgBackupGetPath (prev_backup , prev_file_txt , lengthof (prev_file_txt ),
178
+ DATABASE_FILE_LIST );
179
+ prev_files = dir_read_file_list (pgdata , prev_file_txt );
186
180
187
- /*
188
- * Do backup only pages having larger LSN than previous backup.
189
- */
190
- lsn = & prev_backup -> start_lsn ;
191
- elog (LOG , _ ("backup only the page that there was of the update from LSN(%X/%08X).\n" ),
192
- (uint32 ) (* lsn >> 32 ), (uint32 ) * lsn );
193
- }
181
+ /*
182
+ * Do backup only pages having larger LSN than previous backup.
183
+ */
184
+ lsn = & prev_backup -> start_lsn ;
185
+ elog (LOG , _ ("backup only the page that there was of the update from LSN(%X/%08X).\n" ),
186
+ (uint32 ) (* lsn >> 32 ), (uint32 ) * lsn );
194
187
}
195
188
196
189
/* initialize backup list from non-snapshot */
@@ -455,15 +448,28 @@ do_backup_arclog(parray *backup_list)
455
448
/* initialize size summary */
456
449
current .read_arclog_bytes = 0 ;
457
450
458
- /* switch xlog if database is not backed up */
451
+ /*
452
+ * Switch xlog if database is not backed up, current timeline of
453
+ * server is obtained here.
454
+ */
459
455
if ((uint32 ) current .stop_lsn == 0 )
460
456
pg_switch_xlog (& current );
461
457
458
+ /*
459
+ * Check if there is a full backup present on current timeline.
460
+ * For an incremental or full backup, we are sure that there is one
461
+ * so this error can be bypassed safely.
462
+ */
463
+ if (current .backup_mode == BACKUP_MODE_ARCHIVE &&
464
+ catalog_get_last_data_backup (backup_list , current .tli ) == NULL )
465
+ elog (ERROR_SYSTEM , _ ("No valid full or incremental backup detected "
466
+ "on current timeline " ));
467
+
462
468
/*
463
469
* To take incremental backup, the file list of the last completed
464
470
* database backup is needed.
465
471
*/
466
- prev_backup = catalog_get_last_arclog_backup (backup_list );
472
+ prev_backup = catalog_get_last_arclog_backup (backup_list , current . tli );
467
473
if (verbose && prev_backup == NULL )
468
474
printf (_ ("no previous full backup, performing a full backup instead\n" ));
469
475
@@ -587,7 +593,8 @@ do_backup_srvlog(parray *backup_list)
587
593
* To take incremental backup, the file list of the last completed database
588
594
* backup is needed.
589
595
*/
590
- prev_backup = catalog_get_last_srvlog_backup (backup_list );
596
+ prev_backup = catalog_get_last_srvlog_backup (backup_list ,
597
+ get_current_timeline ());
591
598
if (verbose && prev_backup == NULL )
592
599
printf (_ ("no previous full backup, performing a full backup instead\n" ));
593
600
0 commit comments