@@ -37,6 +37,7 @@ const char *progname;
37
37
/* Options and defaults */
38
38
bool debug = false; /* are we debugging? */
39
39
bool dryrun = false; /* are we performing a dry-run operation? */
40
+ char * additional_ext = NULL ; /* Extension to remove from filenames */
40
41
41
42
char * archiveLocation ; /* where to find the archive? */
42
43
char * restartWALFileName ; /* the file from which we can restart restore */
@@ -90,17 +91,37 @@ Initialize(void)
90
91
}
91
92
}
92
93
94
+ static void
95
+ TrimExtension (char * filename , char * extension )
96
+ {
97
+ int flen ;
98
+ int elen ;
99
+
100
+ if (extension == NULL )
101
+ return ;
102
+
103
+ elen = strlen (extension );
104
+ flen = strlen (filename );
105
+
106
+ if (flen > elen && strcmp (filename + flen - elen , extension ) == 0 )
107
+ filename [flen - elen ] = '\0' ;
108
+ }
109
+
93
110
static void
94
111
CleanupPriorWALFiles (void )
95
112
{
96
113
int rc ;
97
114
DIR * xldir ;
98
115
struct dirent * xlde ;
116
+ char walfile [MAXPGPATH ];
99
117
100
118
if ((xldir = opendir (archiveLocation )) != NULL )
101
119
{
102
120
while ((xlde = readdir (xldir )) != NULL )
103
121
{
122
+ strncpy (walfile , xlde -> d_name , MAXPGPATH );
123
+ TrimExtension (walfile , additional_ext );
124
+
104
125
/*
105
126
* We ignore the timeline part of the XLOG segment identifiers in
106
127
* deciding whether a segment is still needed. This ensures that
@@ -114,10 +135,14 @@ CleanupPriorWALFiles(void)
114
135
* file. Note that this means files are not removed in the order
115
136
* they were originally written, in case this worries you.
116
137
*/
117
- if (strlen (xlde -> d_name ) == XLOG_DATA_FNAME_LEN &&
118
- strspn (xlde -> d_name , "0123456789ABCDEF" ) == XLOG_DATA_FNAME_LEN &&
119
- strcmp (xlde -> d_name + 8 , exclusiveCleanupFileName + 8 ) < 0 )
138
+ if (strlen (walfile ) == XLOG_DATA_FNAME_LEN &&
139
+ strspn (walfile , "0123456789ABCDEF" ) == XLOG_DATA_FNAME_LEN &&
140
+ strcmp (walfile + 8 , exclusiveCleanupFileName + 8 ) < 0 )
120
141
{
142
+ /*
143
+ * Use the original file name again now, including any extension
144
+ * that might have been chopped off before testing the sequence.
145
+ */
121
146
snprintf (WALFilePath , MAXPGPATH , "%s/%s" ,
122
147
archiveLocation , xlde -> d_name );
123
148
@@ -167,6 +192,8 @@ SetWALFileNameForCleanup(void)
167
192
{
168
193
bool fnameOK = false;
169
194
195
+ TrimExtension (restartWALFileName , additional_ext );
196
+
170
197
/*
171
198
* If restartWALFileName is a WAL file name then just use it directly. If
172
199
* restartWALFileName is a .backup filename, make sure we use the prefix
@@ -223,6 +250,7 @@ usage(void)
223
250
printf ("\nOptions:\n" );
224
251
printf (" -d generates debug output (verbose mode)\n" );
225
252
printf (" -n shows the names of the files that would have been removed (dry-run)\n" );
253
+ printf (" -x EXT cleanup files if they have this same extension\n" );
226
254
printf (" --help show this help, then exit\n" );
227
255
printf (" --version output version information, then exit\n" );
228
256
printf ("\n"
@@ -259,7 +287,7 @@ main(int argc, char **argv)
259
287
}
260
288
}
261
289
262
- while ((c = getopt (argc , argv , "dn" )) != -1 )
290
+ while ((c = getopt (argc , argv , "x: dn" )) != -1 )
263
291
{
264
292
switch (c )
265
293
{
@@ -269,6 +297,9 @@ main(int argc, char **argv)
269
297
case 'n' : /* Dry-Run mode */
270
298
dryrun = true;
271
299
break ;
300
+ case 'x' :
301
+ additional_ext = optarg ; /* Extension to remove from xlogfile names */
302
+ break ;
272
303
default :
273
304
fprintf (stderr , "Try \"%s --help\" for more information.\n" , progname );
274
305
exit (2 );
0 commit comments