80 if (extension == NULL)
83 elen = strlen(extension);
86 if (flen > elen && strcmp(
filename + flen - elen, extension) == 0)
100 pg_fatal(
"could not open archive location \"%s\": %m",
103 while (errno = 0, (xlde =
readdir(xldir)) != NULL)
145 snprintf(WALFilePath,
sizeof(WALFilePath),
"%s/%s",
155 printf(
"%s\n", WALFilePath);
156 pg_log_debug(
"file \"%s\" would be removed", WALFilePath);
162 rc = unlink(WALFilePath);
164 pg_fatal(
"could not remove file \"%s\": %m",
169 pg_fatal(
"could not read archive location \"%s\": %m",
172 pg_fatal(
"could not close archive location \"%s\": %m",
185 bool fnameOK =
false;
259 printf(
_(
"%s removes older WAL files from PostgreSQL archives.\n\n"),
progname);
261 printf(
_(
" %s [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILE\n"),
progname);
263 printf(
_(
" -b, --clean-backup-history clean up files including backup history files\n"));
264 printf(
_(
" -d, --debug generate debug output (verbose mode)\n"));
265 printf(
_(
" -n, --dry-run dry run, show the names of the files that would be\n"
267 printf(
_(
" -V, --version output version information, then exit\n"));
268 printf(
_(
" -x, --strip-extension=EXT strip this extention before identifying files for\n"
270 printf(
_(
" -?, --help show this help, then exit\n"));
272 "For use as archive_cleanup_command in postgresql.conf:\n"
273 " archive_cleanup_command = 'pg_archivecleanup [OPTION]... ARCHIVELOCATION %%r'\n"
275 " archive_cleanup_command = 'pg_archivecleanup /mnt/server/archiverdir %%r'\n"));
277 "Or for use as a standalone archive cleaner:\n"
279 " pg_archivecleanup /mnt/server/archiverdir 000000010000000000000010.00000020.backup\n"));
280 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
281 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
288 static struct option long_options[] = {
303 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
308 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
310 puts(
"pg_archivecleanup (PostgreSQL) " PG_VERSION);
315 while ((
c =
getopt_long(argc, argv,
"bdnx:", long_options, NULL)) != -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)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
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)
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)