From 7aaafd2631386bb2bd7e628334a8409fbb648402 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Mon, 5 Feb 2018 14:43:10 +0900
Subject: [PATCH 4/5] Move base backup filter lists into their own header file

This list is for now consumed only by the backend-side base backup code,
which is used to filter out a set of paths and/or files which cannot be
included in base backup data sent to clients.

A follow-up patch will make use of that in pg_rewind itself.
---
 src/backend/replication/basebackup.c       | 82 ++-------------------------
 src/include/replication/basebackup_paths.h | 89 ++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 77 deletions(-)
 create mode 100644 src/include/replication/basebackup_paths.h

diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 2e764ab293..2ea2306cfa 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -28,6 +28,7 @@
 #include "pgstat.h"
 #include "postmaster/syslogger.h"
 #include "replication/basebackup.h"
+#include "replication/basebackup_paths.h"
 #include "replication/walsender.h"
 #include "replication/walsender_private.h"
 #include "storage/dsm_impl.h"
@@ -98,79 +99,6 @@ static TimeOffset elapsed_min_unit;
 /* The last check of the transfer rate. */
 static TimestampTz throttled_last;
 
-/*
- * The contents of these directories are removed or recreated during server
- * start so they are not included in backups.  The directories themselves are
- * kept and included as empty to preserve access permissions.
- */
-static const char *excludeDirContents[] =
-{
-	/*
-	 * Skip temporary statistics files. PG_STAT_TMP_DIR must be skipped even
-	 * when stats_temp_directory is set because PGSS_TEXT_FILE is always
-	 * created there.
-	 */
-	PG_STAT_TMP_DIR,
-
-	/*
-	 * It is generally not useful to backup the contents of this directory
-	 * even if the intention is to restore to another master. See backup.sgml
-	 * for a more detailed description.
-	 */
-	PG_REPLSLOT_DIR,
-
-	/* Contents removed on startup, see dsm_cleanup_for_mmap(). */
-	PG_DYNSHMEM_DIR,
-
-	/* Contents removed on startup, see AsyncShmemInit(). */
-	PG_NOTIFY_DIR,
-
-	/*
-	 * Old contents are loaded for possible debugging but are not required for
-	 * normal operation, see OldSerXidInit().
-	 */
-	PG_SERIAL_DIR,
-
-	/* Contents removed on startup, see DeleteAllExportedSnapshotFiles(). */
-	PG_SNAPSHOTS_DIR,
-
-	/* Contents zeroed on startup, see StartupSUBTRANS(). */
-	PG_SUBTRANS_DIR,
-
-	/* end of list */
-	NULL
-};
-
-/*
- * List of files excluded from backups.
- */
-static const char *excludeFiles[] =
-{
-	/* Skip auto conf temporary file. */
-	PG_AUTOCONF_FILENAME_TMP,
-
-	/* Skip current log file temporary file */
-	LOG_METAINFO_DATAFILE_TMP,
-
-	/* Skip relation cache because it is rebuilt on startup */
-	RELCACHE_INIT_FILENAME,
-
-	/*
-	 * If there's a backup_label or tablespace_map file, it belongs to a
-	 * backup started by the user with pg_start_backup().  It is *not* correct
-	 * for this backup.  Our backup_label/tablespace_map is injected into the
-	 * tar separately.
-	 */
-	BACKUP_LABEL_FILE,
-	TABLESPACE_MAP,
-
-	POSTMASTER_PID_FILE,
-	POSTMASTER_OPTS_FILE,
-
-	/* end of list */
-	NULL
-};
-
 /*
  * Called when ERROR or FATAL happens in perform_base_backup() after
  * we have started the backup - make sure we end it!
@@ -995,9 +923,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
 
 		/* Scan for files that should be excluded */
 		excludeFound = false;
-		for (excludeIdx = 0; excludeFiles[excludeIdx] != NULL; excludeIdx++)
+		for (excludeIdx = 0; backupExcludeFiles[excludeIdx] != NULL; excludeIdx++)
 		{
-			if (strcmp(de->d_name, excludeFiles[excludeIdx]) == 0)
+			if (strcmp(de->d_name, backupExcludeFiles[excludeIdx]) == 0)
 			{
 				elog(DEBUG1, "file \"%s\" excluded from backup", de->d_name);
 				excludeFound = true;
@@ -1028,9 +956,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
 
 		/* Scan for directories whose contents should be excluded */
 		excludeFound = false;
-		for (excludeIdx = 0; excludeDirContents[excludeIdx] != NULL; excludeIdx++)
+		for (excludeIdx = 0; backupExcludeDirs[excludeIdx] != NULL; excludeIdx++)
 		{
-			if (strcmp(de->d_name, excludeDirContents[excludeIdx]) == 0)
+			if (strcmp(de->d_name, backupExcludeDirs[excludeIdx]) == 0)
 			{
 				elog(DEBUG1, "contents of directory \"%s\" excluded from backup", de->d_name);
 				size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
diff --git a/src/include/replication/basebackup_paths.h b/src/include/replication/basebackup_paths.h
new file mode 100644
index 0000000000..64c9f20333
--- /dev/null
+++ b/src/include/replication/basebackup_paths.h
@@ -0,0 +1,89 @@
+/*-------------------------------------------------------------------------
+ *
+ * basebackup_paths.h
+ *	  Filter lists when working on base backups. Can be used by both
+ *	  frontends and backends.
+ *
+ * Portions Copyright (c) 2018, PostgreSQL Global Development Group
+ *
+ * src/include/replication/basebackup_paths.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef _BASEBACKUP_PATHS_H
+#define _BASEBACKUP_PATHS_H
+
+/*
+ * The contents of these directories are removed or recreated during server
+ * start so they are not included in backups.  The directories themselves are
+ * kept and included as empty to preserve access permissions.
+ */
+static const char *backupExcludeDirs[] =
+{
+	/*
+	 * Skip temporary statistics files. PG_STAT_TMP_DIR must be skipped even
+	 * when stats_temp_directory is set because PGSS_TEXT_FILE is always
+	 * created there.
+	 */
+	PG_STAT_TMP_DIR,
+
+	/*
+	 * It is generally not useful to backup the contents of this directory
+	 * even if the intention is to restore to another master. See backup.sgml
+	 * for a more detailed description.
+	 */
+	PG_REPLSLOT_DIR,
+
+	/* Contents removed on startup, see dsm_cleanup_for_mmap(). */
+	PG_DYNSHMEM_DIR,
+
+	/* Contents removed on startup, see AsyncShmemInit(). */
+	PG_NOTIFY_DIR,
+
+	/*
+	 * Old contents are loaded for possible debugging but are not required for
+	 * normal operation, see OldSerXidInit().
+	 */
+	PG_SERIAL_DIR,
+
+	/* Contents removed on startup, see DeleteAllExportedSnapshotFiles(). */
+	PG_SNAPSHOTS_DIR,
+
+	/* Contents zeroed on startup, see StartupSUBTRANS(). */
+	PG_SUBTRANS_DIR,
+
+	/* end of list */
+	NULL
+};
+
+/*
+ * List of files excluded from base backups.
+ */
+static const char *backupExcludeFiles[] =
+{
+	/* Skip auto conf temporary file. */
+	PG_AUTOCONF_FILENAME_TMP,
+
+	/* Skip current log file temporary file */
+	LOG_METAINFO_DATAFILE_TMP,
+
+	/* Skip relation cache because it is rebuilt on startup */
+	RELCACHE_INIT_FILENAME,
+
+	/*
+	 * If there's a backup_label or tablespace_map file, it belongs to a
+	 * backup started by the user with pg_start_backup().  It is *not* correct
+	 * for this backup.  Our backup_label/tablespace_map is injected into the
+	 * tar separately.
+	 */
+	BACKUP_LABEL_FILE,
+	TABLESPACE_MAP,
+
+	POSTMASTER_PID_FILE,
+	POSTMASTER_OPTS_FILE,
+
+	/* end of list */
+	NULL
+};
+
+#endif							/* _BASEBACKUP_PATHS_H */
-- 
2.16.1

