1
1
/*
2
- * $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.2 2010/06/17 17:31:27 tgl Exp $
2
+ * $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.3 2010/07/06 19:18:55 momjian Exp $
3
3
*
4
4
* pg_archivecleanup.c
5
5
*
@@ -40,8 +40,9 @@ bool debug = false; /* are we debugging? */
40
40
char * archiveLocation ; /* where to find the archive? */
41
41
char * restartWALFileName ; /* the file from which we can restart restore */
42
42
char WALFilePath [MAXPGPATH ]; /* the file path including archive */
43
- char exclusiveCleanupFileName [MAXPGPATH ]; /* the oldest file we want to
44
- * remain in archive */
43
+ char exclusiveCleanupFileName [MAXPGPATH ]; /* the oldest file we
44
+ * want to remain in
45
+ * archive */
45
46
46
47
47
48
/* =====================================================================
@@ -68,14 +69,14 @@ char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we want to
68
69
/*
69
70
* Initialize allows customized commands into the archive cleanup program.
70
71
*
71
- * You may wish to add code to check for tape libraries, etc..
72
+ * You may wish to add code to check for tape libraries, etc..
72
73
*/
73
74
static void
74
75
Initialize (void )
75
76
{
76
77
/*
77
- * This code assumes that archiveLocation is a directory, so we use
78
- * stat to test if it's accessible.
78
+ * This code assumes that archiveLocation is a directory, so we use stat
79
+ * to test if it's accessible.
79
80
*/
80
81
struct stat stat_buf ;
81
82
@@ -100,22 +101,21 @@ CleanupPriorWALFiles(void)
100
101
while ((xlde = readdir (xldir )) != NULL )
101
102
{
102
103
/*
103
- * We ignore the timeline part of the XLOG segment identifiers
104
- * in deciding whether a segment is still needed. This
105
- * ensures that we won't prematurely remove a segment from a
106
- * parent timeline. We could probably be a little more
107
- * proactive about removing segments of non-parent timelines,
108
- * but that would be a whole lot more complicated.
104
+ * We ignore the timeline part of the XLOG segment identifiers in
105
+ * deciding whether a segment is still needed. This ensures that
106
+ * we won't prematurely remove a segment from a parent timeline.
107
+ * We could probably be a little more proactive about removing
108
+ * segments of non-parent timelines, but that would be a whole lot
109
+ * more complicated.
109
110
*
110
- * We use the alphanumeric sorting property of the filenames
111
- * to decide which ones are earlier than the
112
- * exclusiveCleanupFileName file. Note that this means files
113
- * are not removed in the order they were originally written,
114
- * in case this worries you.
111
+ * We use the alphanumeric sorting property of the filenames to
112
+ * decide which ones are earlier than the exclusiveCleanupFileName
113
+ * file. Note that this means files are not removed in the order
114
+ * they were originally written, in case this worries you.
115
115
*/
116
116
if (strlen (xlde -> d_name ) == XLOG_DATA_FNAME_LEN &&
117
- strspn (xlde -> d_name , "0123456789ABCDEF" ) == XLOG_DATA_FNAME_LEN &&
118
- strcmp (xlde -> d_name + 8 , exclusiveCleanupFileName + 8 ) < 0 )
117
+ strspn (xlde -> d_name , "0123456789ABCDEF" ) == XLOG_DATA_FNAME_LEN &&
118
+ strcmp (xlde -> d_name + 8 , exclusiveCleanupFileName + 8 ) < 0 )
119
119
{
120
120
#ifdef WIN32
121
121
snprintf (WALFilePath , MAXPGPATH , "%s\\%s" , archiveLocation , xlde -> d_name );
@@ -152,13 +152,13 @@ CleanupPriorWALFiles(void)
152
152
static void
153
153
SetWALFileNameForCleanup (void )
154
154
{
155
- bool fnameOK = false;
155
+ bool fnameOK = false;
156
156
157
157
/*
158
- * If restartWALFileName is a WAL file name then just use it directly.
159
- * If restartWALFileName is a .backup filename, make sure we use
160
- * the prefix of the filename, otherwise we will remove wrong files
161
- * since 000000010000000000000010.00000020.backup is after
158
+ * If restartWALFileName is a WAL file name then just use it directly. If
159
+ * restartWALFileName is a .backup filename, make sure we use the prefix
160
+ * of the filename, otherwise we will remove wrong files since
161
+ * 000000010000000000000010.00000020.backup is after
162
162
* 000000010000000000000010.
163
163
*/
164
164
if (strlen (restartWALFileName ) == XLOG_DATA_FNAME_LEN &&
@@ -169,17 +169,20 @@ SetWALFileNameForCleanup(void)
169
169
}
170
170
else if (strlen (restartWALFileName ) == XLOG_BACKUP_FNAME_LEN )
171
171
{
172
- int args ;
172
+ int args ;
173
173
uint32 tli = 1 ,
174
174
log = 0 ,
175
175
seg = 0 ,
176
176
offset = 0 ;
177
+
177
178
args = sscanf (restartWALFileName , "%08X%08X%08X.%08X.backup" , & tli , & log , & seg , & offset );
178
179
if (args == 4 )
179
180
{
180
181
fnameOK = true;
182
+
181
183
/*
182
- * Use just the prefix of the filename, ignore everything after first period
184
+ * Use just the prefix of the filename, ignore everything after
185
+ * first period
183
186
*/
184
187
XLogFileName (exclusiveCleanupFileName , tli , log , seg );
185
188
}
@@ -205,12 +208,12 @@ usage(void)
205
208
printf ("Usage:\n" );
206
209
printf (" %s [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILE\n" , progname );
207
210
printf ("\n"
208
- "for use as an archive_cleanup_command in the recovery.conf when standby_mode = on:\n"
211
+ "for use as an archive_cleanup_command in the recovery.conf when standby_mode = on:\n"
209
212
" archive_cleanup_command = 'pg_archivecleanup [OPTION]... ARCHIVELOCATION %%r'\n"
210
213
"e.g.\n"
211
214
" archive_cleanup_command = 'pg_archivecleanup /mnt/server/archiverdir %%r'\n" );
212
215
printf ("\n"
213
- "or for use as a standalone archive cleaner:\n"
216
+ "or for use as a standalone archive cleaner:\n"
214
217
"e.g.\n"
215
218
" pg_archivecleanup /mnt/server/archiverdir 000000010000000000000010.00000020.backup\n" );
216
219
printf ("\nOptions:\n" );
@@ -258,9 +261,10 @@ main(int argc, char **argv)
258
261
259
262
/*
260
263
* We will go to the archiveLocation to check restartWALFileName.
261
- * restartWALFileName may not exist anymore, which would not be an error, so
262
- * we separate the archiveLocation and restartWALFileName so we can check
263
- * separately whether archiveLocation exists, if not that is an error
264
+ * restartWALFileName may not exist anymore, which would not be an error,
265
+ * so we separate the archiveLocation and restartWALFileName so we can
266
+ * check separately whether archiveLocation exists, if not that is an
267
+ * error
264
268
*/
265
269
if (optind < argc )
266
270
{
0 commit comments