Hi guys,

I have added the '-n' option to pg_archivecleanup which performs a dry-run and outputs the names of the files to be removed to stdout (making possible to pass the list via pipe to another process).

  Please find attached the small patch. I submit it to the CommitFest.

Thanks,
Gabriele

--
  Gabriele Bartolini - 2ndQuadrant Italia
  PostgreSQL Training, Services and Support
  gabriele.bartol...@2ndquadrant.it | www.2ndQuadrant.it


*** 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>
  
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to