diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 1008873..5163b85 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -970,9 +970,25 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
 		  strncmp(de->d_name, PG_STAT_TMP_DIR, strlen(PG_STAT_TMP_DIR)) == 0)
 		{
 			if (!sizeonly)
-				_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
-			size += 512;
-			continue;
+			{
+				/* If pg_stat_tmp is a symlink, skip it */
+#ifndef WIN32
+				if (S_ISLNK(statbuf.st_mode))
+#else
+				if (pgwin32_is_junction(pathbuf))
+#endif
+				{
+					ereport(WARNING,
+						(errmsg("skipping special file \"%s\"", pathbuf)));
+					continue;
+				}
+				else
+				{
+					_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
+					size += 512;
+					continue;
+				}
+			}
 		}
 
 		/*
@@ -982,9 +998,25 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
 		if (strcmp(de->d_name, "pg_replslot") == 0)
 		{
 			if (!sizeonly)
-				_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
-			size += 512;		/* Size of the header just added */
-			continue;
+			{
+				/* If pg_replslot is a symlink, skip it */
+#ifndef WIN32
+				if (S_ISLNK(statbuf.st_mode))
+#else
+				if (pgwin32_is_junction(pathbuf))
+#endif
+				{
+					ereport(WARNING,
+						(errmsg("skipping special file \"%s\"", pathbuf)));
+					continue;
+				}
+				else
+				{
+					_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
+					size += 512;		/* Size of the header just added */
+					continue;
+				}
+			}
 		}
 
 		/*
