78 if (extension == NULL)
81 elen = strlen(extension);
84 if (flen > elen && strcmp(
filename + flen - elen, extension) == 0)
98 while (errno = 0, (xlde =
readdir(xldir)) != NULL)
132 snprintf(WALFilePath,
sizeof(WALFilePath),
"%s/%s",
142 printf(
"%s\n", WALFilePath);
143 pg_log_debug(
"file \"%s\" would be removed", WALFilePath);
149 rc = unlink(WALFilePath);
151 pg_fatal(
"could not remove file \"%s\": %m",
157 pg_fatal(
"could not read archive location \"%s\": %m",
160 pg_fatal(
"could not close archive location \"%s\": %m",
164 pg_fatal(
"could not open archive location \"%s\": %m",
177 bool fnameOK =
false;
251 printf(
_(
"%s removes older WAL files from PostgreSQL archives.\n\n"),
progname);
253 printf(
_(
" %s [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILE\n"),
progname);
255 printf(
_(
" -d generate debug output (verbose mode)\n"));
256 printf(
_(
" -n dry run, show the names of the files that would be removed\n"));
257 printf(
_(
" -V, --version output version information, then exit\n"));
258 printf(
_(
" -x EXT clean up files if they have this extension\n"));
259 printf(
_(
" -?, --help show this help, then exit\n"));
261 "For use as archive_cleanup_command in postgresql.conf:\n"
262 " archive_cleanup_command = 'pg_archivecleanup [OPTION]... ARCHIVELOCATION %%r'\n"
264 " archive_cleanup_command = 'pg_archivecleanup /mnt/server/archiverdir %%r'\n"));
266 "Or for use as a standalone archive cleaner:\n"
268 " pg_archivecleanup /mnt/server/archiverdir 000000010000000000000010.00000020.backup\n"));
269 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
270 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
285 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
290 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
292 puts(
"pg_archivecleanup (PostgreSQL) " PG_VERSION);
297 while ((
c =
getopt(argc, argv,
"dnx:")) != -1)
#define PG_TEXTDOMAIN(domain)
void set_pglocale_pgservice(const char *argv0, const char *app)
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
char * pg_strdup(const char *in)
void pg_logging_increase_verbosity(void)
void pg_logging_init(const char *argv0)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define pg_log_debug(...)
char * restartWALFileName
int main(int argc, char **argv)
char exclusiveCleanupFileName[MAXFNAMELEN]
static void SetWALFileNameForCleanup(void)
static void CleanupPriorWALFiles(void)
static void Initialize(void)
static void TrimExtension(char *filename, char *extension)
int getopt(int nargc, char *const *nargv, const char *ostr)
PGDLLIMPORT char * optarg
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
static bool IsXLogFileName(const char *fname)
static bool IsBackupHistoryFileName(const char *fname)
static void XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
static bool IsPartialXLogFileName(const char *fname)