add-dry-run-option-pgarchivecleanup-v2.patch

text/plain

Filename: add-dry-run-option-pgarchivecleanup-v2.patch
Type: text/plain
Part: 0
Message: Re: 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
Series: patch v2
File+
contrib/pg_archivecleanup/pg_archivecleanup.c 18 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 */
***************
*** 119,124 **** CleanupPriorWALFiles(void)
--- 120,137 ----
  			{
  				snprintf(WALFilePath, MAXPGPATH, "%s/%s",
  						 archiveLocation, xlde->d_name);
+ 
+ 				if (dryrun)
+ 				{
+ 					/* Prints the name of the file and
+ 					 * skips the actual removal of the file */
+ 					fprintf(stdout, "%s\n", WALFilePath);
+ 					if (debug)
+ 						fprintf(stderr, "%s: dry-run mode suggests removing file \"%s\"\n",
+ 								progname, WALFilePath);
+ 					continue;
+ 				}
+ 
  				if (debug)
  					fprintf(stderr, "%s: removing file \"%s\"\n",
  							progname, WALFilePath);
***************
*** 205,210 **** usage(void)
--- 218,224 ----
  	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);
--- 255,270 ----
  		}
  	}
  
! 	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>