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.

Thanks,
Gabriele

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

>From 25fcf05ff787dae2b0d62de423a363f8597f1d42 Mon Sep 17 00:00:00 2001
From: Gabriele Bartolini <gabriele.bartol...@2ndquadrant.it>
Date: Mon, 27 Jun 2011 12:27:09 +0200
Subject: [PATCH] Add dryrun option to pg_archivecleanup

---
 contrib/pg_archivecleanup/pg_archivecleanup.c |   13 ++++++++++++-
 doc/src/sgml/pgarchivecleanup.sgml            |    9 +++++++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/contrib/pg_archivecleanup/pg_archivecleanup.c 
b/contrib/pg_archivecleanup/pg_archivecleanup.c
index dd8a451..0bbec92 100644
--- a/contrib/pg_archivecleanup/pg_archivecleanup.c
+++ b/contrib/pg_archivecleanup/pg_archivecleanup.c
@@ -36,6 +36,7 @@ const char *progname;
 
 /* 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,6 +124,12 @@ CleanupPriorWALFiles(void)
                                        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,6 +212,7 @@ usage(void)
        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,13 +249,16 @@ main(int argc, char **argv)
                }
        }
 
-       while ((c = getopt(argc, argv, "d")) != -1)
+       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);
diff --git a/doc/src/sgml/pgarchivecleanup.sgml 
b/doc/src/sgml/pgarchivecleanup.sgml
index ddffa32..8148c53 100644
--- a/doc/src/sgml/pgarchivecleanup.sgml
+++ b/doc/src/sgml/pgarchivecleanup.sgml
@@ -98,6 +98,15 @@ pg_archivecleanup:  removing file 
"archive/00000001000000370000000E"
       </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>
 
-- 
1.7.4.1

-- 
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