3
3
* archive.c: - pg_probackup specific archive commands for archive backups.
4
4
*
5
5
*
6
- * Portions Copyright (c) 2018-2019 , Postgres Professional
6
+ * Portions Copyright (c) 2018-2021 , Postgres Professional
7
7
*
8
8
*-------------------------------------------------------------------------
9
9
*/
@@ -140,15 +140,13 @@ get_xlogFileType(const char *filename)
140
140
* Where archlog_path is $BACKUP_PATH/wal/instance_name
141
141
*/
142
142
void
143
- do_archive_push (InstanceState * instanceState , InstanceConfig * instance , char * wal_file_path ,
143
+ do_archive_push (InstanceState * instanceState , InstanceConfig * instance , char * pg_xlog_dir ,
144
144
char * wal_file_name , int batch_size , bool overwrite ,
145
145
bool no_sync , bool no_ready_rename )
146
146
{
147
147
uint64 i ;
148
- char current_dir [MAXPGPATH ];
149
- char pg_xlog_dir [MAXPGPATH ];
150
- char archive_status_dir [MAXPGPATH ];
151
- uint64 system_id ;
148
+ /* usually instance pgdata/pg_wal/archive_status, empty if no_ready_rename or batch_size == 1 */
149
+ char archive_status_dir [MAXPGPATH ] = "" ;
152
150
bool is_compress = false;
153
151
154
152
/* arrays with meta info for multi threaded backup */
@@ -169,31 +167,8 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
169
167
parray * archive_subdirs = NULL ;
170
168
int n_threads ;
171
169
172
- if (wal_file_name == NULL )
173
- elog (ERROR , "Required parameter is not specified: --wal-file-name %%f" );
174
-
175
- if (!getcwd (current_dir , sizeof (current_dir )))
176
- elog (ERROR , "getcwd() error" );
177
-
178
- /* verify that archive-push --instance parameter is valid */
179
- system_id = get_system_identifier (current_dir , FIO_DB_HOST );
180
-
181
- if (instance -> pgdata == NULL )
182
- elog (ERROR , "Cannot read pg_probackup.conf for this instance" );
183
-
184
- if (system_id != instance -> system_identifier )
185
- elog (ERROR , "Refuse to push WAL segment %s into archive. Instance parameters mismatch."
186
- "Instance '%s' should have SYSTEM_ID = " UINT64_FORMAT " instead of " UINT64_FORMAT ,
187
- wal_file_name , instanceState -> instance_name , instance -> system_identifier , system_id );
188
-
189
- if (instance -> compress_alg == PGLZ_COMPRESS )
190
- elog (ERROR , "Cannot use pglz for WAL compression" );
191
-
192
- join_path_components (pg_xlog_dir , current_dir , XLOGDIR );
193
- join_path_components (archive_status_dir , pg_xlog_dir , "archive_status" );
194
-
195
- /* Create 'archlog_path' directory. Do nothing if it already exists. */
196
- //fio_mkdir(instanceState->instance_wal_subdir_path, DIR_PERMISSION, FIO_BACKUP_HOST);
170
+ if (!no_ready_rename || batch_size > 1 )
171
+ join_path_components (archive_status_dir , pg_xlog_dir , "archive_status" );
197
172
198
173
#ifdef HAVE_LIBZ
199
174
if (instance -> compress_alg == ZLIB_COMPRESS )
@@ -246,12 +221,13 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
246
221
{
247
222
int rc ;
248
223
WALSegno * xlogfile = (WALSegno * ) parray_get (batch_files , i );
224
+ bool first_wal = strcmp (xlogfile -> name , wal_file_name ) == 0 ;
249
225
250
- rc = push_file (xlogfile , archive_status_dir ,
226
+ rc = push_file (xlogfile , first_wal ? NULL : archive_status_dir ,
251
227
pg_xlog_dir , instanceState -> instance_wal_subdir_path ,
252
228
overwrite , no_sync ,
253
229
instance -> archive_timeout ,
254
- no_ready_rename || ( strcmp ( xlogfile -> name , wal_file_name ) == 0 ) ? true : false ,
230
+ no_ready_rename || first_wal ,
255
231
is_compress && IsXLogFileName (xlogfile -> name ) ? true : false,
256
232
instance -> compress_level );
257
233
if (rc == 0 )
@@ -275,7 +251,7 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
275
251
arg -> first_filename = wal_file_name ;
276
252
arg -> archive_dir = instanceState -> instance_wal_subdir_path ;
277
253
arg -> pg_xlog_dir = pg_xlog_dir ;
278
- arg -> archive_status_dir = archive_status_dir ;
254
+ arg -> archive_status_dir = (! no_ready_rename || batch_size > 1 ) ? archive_status_dir : NULL ;
279
255
arg -> overwrite = overwrite ;
280
256
arg -> compress = is_compress ;
281
257
arg -> no_sync = no_sync ;
@@ -318,7 +294,7 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
318
294
319
295
/* Note, that we are leaking memory here,
320
296
* because pushing into archive is a very
321
- * time-sensetive operation, so we skip freeing stuff.
297
+ * time-sensitive operation, so we skip freeing stuff.
322
298
*/
323
299
324
300
push_done :
@@ -398,9 +374,6 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
398
374
int compress_level )
399
375
{
400
376
int rc ;
401
- char wal_file_dummy [MAXPGPATH ];
402
-
403
- join_path_components (wal_file_dummy , archive_status_dir , xlogfile -> name );
404
377
405
378
elog (LOG , "pushing file \"%s\"" , xlogfile -> name );
406
379
@@ -417,11 +390,13 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
417
390
#endif
418
391
419
392
/* take '--no-ready-rename' flag into account */
420
- if (!no_ready_rename )
393
+ if (!no_ready_rename && archive_status_dir != NULL )
421
394
{
395
+ char wal_file_dummy [MAXPGPATH ];
422
396
char wal_file_ready [MAXPGPATH ];
423
397
char wal_file_done [MAXPGPATH ];
424
398
399
+ join_path_components (wal_file_dummy , archive_status_dir , xlogfile -> name );
425
400
snprintf (wal_file_ready , MAXPGPATH , "%s.%s" , wal_file_dummy , "ready" );
426
401
snprintf (wal_file_done , MAXPGPATH , "%s.%s" , wal_file_dummy , "done" );
427
402
0 commit comments