33 * archive.c: - pg_probackup specific archive commands for archive backups.
44 *
55 *
6- * Portions Copyright (c) 2018-2019 , Postgres Professional
6+ * Portions Copyright (c) 2018-2021 , Postgres Professional
77 *
88 *-------------------------------------------------------------------------
99 */
@@ -140,15 +140,13 @@ get_xlogFileType(const char *filename)
140140 * Where archlog_path is $BACKUP_PATH/wal/instance_name
141141 */
142142void
143- do_archive_push (InstanceState * instanceState ,InstanceConfig * instance ,char * wal_file_path ,
143+ do_archive_push (InstanceState * instanceState ,InstanceConfig * instance ,char * pg_xlog_dir ,
144144char * wal_file_name ,int batch_size ,bool overwrite ,
145145bool no_sync ,bool no_ready_rename )
146146{
147147uint64 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 ]= "" ;
152150bool is_compress = false;
153151
154152/* arrays with meta info for multi threaded backup */
@@ -169,31 +167,8 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
169167parray * archive_subdirs = NULL ;
170168int n_threads ;
171169
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" );
197172
198173#ifdef HAVE_LIBZ
199174if (instance -> compress_alg == ZLIB_COMPRESS )
@@ -246,12 +221,13 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
246221{
247222int rc ;
248223WALSegno * xlogfile = (WALSegno * )parray_get (batch_files ,i );
224+ bool first_wal = strcmp (xlogfile -> name ,wal_file_name )== 0 ;
249225
250- rc = push_file (xlogfile ,archive_status_dir ,
226+ rc = push_file (xlogfile ,first_wal ? NULL : archive_status_dir ,
251227pg_xlog_dir ,instanceState -> instance_wal_subdir_path ,
252228overwrite ,no_sync ,
253229instance -> archive_timeout ,
254- no_ready_rename || ( strcmp ( xlogfile -> name , wal_file_name ) == 0 ) ? true : false ,
230+ no_ready_rename || first_wal ,
255231is_compress && IsXLogFileName (xlogfile -> name ) ? true : false,
256232instance -> compress_level );
257233if (rc == 0 )
@@ -275,7 +251,7 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
275251arg -> first_filename = wal_file_name ;
276252arg -> archive_dir = instanceState -> instance_wal_subdir_path ;
277253arg -> 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 ;
279255arg -> overwrite = overwrite ;
280256arg -> compress = is_compress ;
281257arg -> no_sync = no_sync ;
@@ -318,7 +294,7 @@ do_archive_push(InstanceState *instanceState, InstanceConfig *instance, char *wa
318294
319295/* Note, that we are leaking memory here,
320296 * 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.
322298 */
323299
324300push_done :
@@ -398,9 +374,6 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
398374int compress_level )
399375{
400376int rc ;
401- char wal_file_dummy [MAXPGPATH ];
402-
403- join_path_components (wal_file_dummy ,archive_status_dir ,xlogfile -> name );
404377
405378elog (LOG ,"pushing file \"%s\"" ,xlogfile -> name );
406379
@@ -417,11 +390,13 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
417390#endif
418391
419392/* take '--no-ready-rename' flag into account */
420- if (!no_ready_rename )
393+ if (!no_ready_rename && archive_status_dir != NULL )
421394{
395+ char wal_file_dummy [MAXPGPATH ];
422396char wal_file_ready [MAXPGPATH ];
423397char wal_file_done [MAXPGPATH ];
424398
399+ join_path_components (wal_file_dummy ,archive_status_dir ,xlogfile -> name );
425400snprintf (wal_file_ready ,MAXPGPATH ,"%s.%s" ,wal_file_dummy ,"ready" );
426401snprintf (wal_file_done ,MAXPGPATH ,"%s.%s" ,wal_file_dummy ,"done" );
427402