add-dry-run-option-pgarchivecleanup.patch
text/plain
Filename: add-dry-run-option-pgarchivecleanup.patch
Type: text/plain
Part: 0
Message:
Dry-run mode for pg_archivecleanup
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| contrib/pg_archivecleanup/pg_archivecleanup.c | 13 | 0 |
| doc/src/sgml/pgarchivecleanup.sgml | 9 | 0 |
*** a/contrib/pg_archivecleanup/pg_archivecleanup.c
--- b/contrib/pg_archivecleanup/pg_archivecleanup.c
***************
*** 36,41 **** const char *progname;
--- 36,42 ----
/* Options and defaults */
bool debug = false; /* are we debugging? */
+ bool dryrun = false; /* are we performing a dry-run operation? */
char *archiveLocation; /* where to find the archive? */
char *restartWALFileName; /* the file from which we can restart restore */
***************
*** 123,128 **** CleanupPriorWALFiles(void)
--- 124,136 ----
fprintf(stderr, "%s: removing file \"%s\"\n",
progname, WALFilePath);
+ if (dryrun)
+ {
+ /* Prints the name of the file and
+ * skips the actual removal of the file */
+ fprintf(stdout, "%s\n", WALFilePath);
+ continue;
+ }
rc = unlink(WALFilePath);
if (rc != 0)
{
***************
*** 205,210 **** usage(void)
--- 213,219 ----
printf(" %s [OPTION]... ARCHIVELOCATION OLDESTKEPTWALFILE\n", progname);
printf("\nOptions:\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(" --version output version information, then exit\n");
printf("\n"
***************
*** 241,253 **** main(int argc, char **argv)
}
}
! while ((c = getopt(argc, argv, "d")) != -1)
{
switch (c)
{
case 'd': /* Debug mode */
debug = true;
break;
default:
fprintf(stderr, "Try \"%s --help\" for more information.\n", progname);
exit(2);
--- 250,265 ----
}
}
! while ((c = getopt(argc, argv, "dn")) != -1)
{
switch (c)
{
case 'd': /* Debug mode */
debug = true;
break;
+ case 'n': /* Dry-Run mode */
+ dryrun = true;
+ break;
default:
fprintf(stderr, "Try \"%s --help\" for more information.\n", progname);
exit(2);
*** a/doc/src/sgml/pgarchivecleanup.sgml
--- b/doc/src/sgml/pgarchivecleanup.sgml
***************
*** 98,103 **** pg_archivecleanup: removing file "archive/00000001000000370000000E"
--- 98,112 ----
</listitem>
</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>
</para>