81 if (extension == NULL)
84 elen = strlen(extension);
87 if (flen > elen && strcmp(
filename + flen - elen, extension) == 0)
101 pg_fatal(
"could not open archive location \"%s\": %m",
104 while (errno = 0, (xlde =
readdir(xldir)) != NULL)
146 snprintf(WALFilePath,
sizeof(WALFilePath),
"%s/%s",
156 printf(
"%s\n", WALFilePath);
157 pg_log_debug(
"file \"%s\" would be removed", WALFilePath);
163 rc = unlink(WALFilePath);
165 pg_fatal(
"could not remove file \"%s\": %m",
170 pg_fatal(
"could not read archive location \"%s\": %m",
173 pg_fatal(
"could not close archive location \"%s\": %m",
186 bool fnameOK =
false;
260 printf(
_(
"%s removes older WAL files from PostgreSQL archives.\n\n"),
progname);
262 printf(
_(
" %s [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILE\n"),
progname);
264 printf(
_(
" -b, --clean-backup-history clean up files including backup history files\n"));
265 printf(
_(
" -d, --debug generate debug output (verbose mode)\n"));
266 printf(
_(
" -n, --dry-run dry run, show the names of the files that would be\n"
268 printf(
_(
" -V, --version output version information, then exit\n"));
269 printf(
_(
" -x, --strip-extension=EXT strip this extension before identifying files for\n"
271 printf(
_(
" -?, --help show this help, then exit\n"));
273 "For use as \"archive_cleanup_command\" in postgresql.conf:\n"
274 " archive_cleanup_command = 'pg_archivecleanup [OPTION]... ARCHIVELOCATION %%r'\n"
276 " archive_cleanup_command = 'pg_archivecleanup /mnt/server/archiverdir %%r'\n"));
278 "Or for use as a standalone archive cleaner:\n"
280 " pg_archivecleanup /mnt/server/archiverdir 000000010000000000000010.00000020.backup\n"));
281 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
282 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
289 static struct option long_options[] = {
304 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
309 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
311 puts(
"pg_archivecleanup (PostgreSQL) " PG_VERSION);
316 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(...)
static char * restartWALFileName
int main(int argc, char **argv)
static char * archiveLocation
static char * additional_ext
static bool cleanBackupHistory
static char exclusiveCleanupFileName[MAXFNAMELEN]
static void SetWALFileNameForCleanup(void)
static void CleanupPriorWALFiles(void)
static void Initialize(void)
static const char * progname
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)