Implement dry-run mode for pg_archivecleanup
In dry-run mode, just the name of the file to be removed is printed to stdout; this is so the user can easily plug it into another program through a pipe. If debug mode is also specified, a more verbose message is printed to stderr. Author: Gabriele Bartolini Reviewer: Josh Kupershmidt
This commit is contained in:
parent
21238deea5
commit
b2e431a4db
|
@ -36,6 +36,7 @@ const char *progname;
|
||||||
|
|
||||||
/* Options and defaults */
|
/* Options and defaults */
|
||||||
bool debug = false; /* are we debugging? */
|
bool debug = false; /* are we debugging? */
|
||||||
|
bool dryrun = false; /* are we performing a dry-run operation? */
|
||||||
|
|
||||||
char *archiveLocation; /* where to find the archive? */
|
char *archiveLocation; /* where to find the archive? */
|
||||||
char *restartWALFileName; /* the file from which we can restart restore */
|
char *restartWALFileName; /* the file from which we can restart restore */
|
||||||
|
@ -119,6 +120,22 @@ CleanupPriorWALFiles(void)
|
||||||
{
|
{
|
||||||
snprintf(WALFilePath, MAXPGPATH, "%s/%s",
|
snprintf(WALFilePath, MAXPGPATH, "%s/%s",
|
||||||
archiveLocation, xlde->d_name);
|
archiveLocation, xlde->d_name);
|
||||||
|
|
||||||
|
if (dryrun)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Prints the name of the file to be removed and skips the
|
||||||
|
* actual removal. The regular printout is so that the
|
||||||
|
* user can pipe the output into some other program.
|
||||||
|
*/
|
||||||
|
printf("%s\n", WALFilePath);
|
||||||
|
if (debug)
|
||||||
|
fprintf(stderr,
|
||||||
|
"%s: file \"%s\" would be removed\n",
|
||||||
|
progname, WALFilePath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "%s: removing file \"%s\"\n",
|
fprintf(stderr, "%s: removing file \"%s\"\n",
|
||||||
progname, WALFilePath);
|
progname, WALFilePath);
|
||||||
|
@ -205,6 +222,7 @@ usage(void)
|
||||||
printf(" %s [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILE\n", progname);
|
printf(" %s [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILE\n", progname);
|
||||||
printf("\nOptions:\n");
|
printf("\nOptions:\n");
|
||||||
printf(" -d generates debug output (verbose mode)\n");
|
printf(" -d generates debug output (verbose mode)\n");
|
||||||
|
printf(" -n shows the names of the files that would have been removed (dry-run)\n");
|
||||||
printf(" --help show this help, then exit\n");
|
printf(" --help show this help, then exit\n");
|
||||||
printf(" --version output version information, then exit\n");
|
printf(" --version output version information, then exit\n");
|
||||||
printf("\n"
|
printf("\n"
|
||||||
|
@ -241,13 +259,16 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "d")) != -1)
|
while ((c = getopt(argc, argv, "dn")) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'd': /* Debug mode */
|
case 'd': /* Debug mode */
|
||||||
debug = true;
|
debug = true;
|
||||||
break;
|
break;
|
||||||
|
case 'n': /* Dry-Run mode */
|
||||||
|
dryrun = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Try \"%s --help\" for more information.\n", progname);
|
fprintf(stderr, "Try \"%s --help\" for more information.\n", progname);
|
||||||
exit(2);
|
exit(2);
|
||||||
|
|
|
@ -98,6 +98,15 @@ pg_archivecleanup: removing file "archive/00000001000000370000000E"
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>-n</option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Print the names of the files that would have been removed on <filename>stdout</> (performs a dry run).
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue