Hi,

Knowing that pg_basebackup always creates an empty directory for
pg_stat_tmp and pg_replslot in backup location, even i think it would be
better to handle these directories in such a way that pg_basebackup
generates an empty directory for pg_replslot and pg_stat_tmp if they are
symbolic link.

PFA patch for the same.

With Regards,
Ashutosh Sharma
EnterpriseDB: *http://www.enterprisedb.com <http://www.enterprisedb.com>*

On Thu, Apr 14, 2016 at 11:57 PM, Magnus Hagander <mag...@hagander.net>
wrote:

> On Thu, Apr 14, 2016 at 8:20 PM, Ashutosh Sharma <ashu.coe...@gmail.com>
> wrote:
>
>> Hi,
>>
>> I was just curious to know how would "*pg_basebackup*" behave if we do
>> create a symbolic link for directories other than pg_xlog/pg_tblspc.
>> However it is clearly mentioned in the documentation of pg_basebackup that
>> if a  Symbolic link for the directories other than pg_tblspc and pg_xlog is
>> created then it would be skipped. But, that is not the case for pg_replslot
>> and pg_stat_tmp. Is this not an issue. Should these directories not be
>> skipped. Please let me know your thoughts on this. Thanks.
>>
>
> I agree that actually generating a corrupt tarfile is not good. But I
> think the correct fix is to actually generate an empty placeholder
> directory rather than skipping it - thereby making the backup look the same
> as it would if it was a correct directory where we just skipped the
> contents.
>
> --
>  Magnus Hagander
>  Me: http://www.hagander.net/
>  Work: http://www.redpill-linpro.com/
>
diff --git a/src/backend/replication/basebackup.c 
b/src/backend/replication/basebackup.c
index 1008873..5e3932b 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -970,7 +970,16 @@ 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)
+                       {
+                               /* If pg_stat_tmp is a symlink, write it as a 
directory anyway */
+#ifndef WIN32
+                               if (S_ISLNK(statbuf.st_mode))
+#else
+                               if (pgwin32_is_junction(pathbuf))
+#endif
+                                       statbuf.st_mode = S_IFDIR | S_IRWXU;
                                _tarWriteHeader(pathbuf + basepathlen + 1, 
NULL, &statbuf);
+                       }
                        size += 512;
                        continue;
                }
@@ -982,7 +991,16 @@ sendDir(char *path, int basepathlen, bool sizeonly, List 
*tablespaces,
                if (strcmp(de->d_name, "pg_replslot") == 0)
                {
                        if (!sizeonly)
+                       {
+                               /* If pg_replslot is a symlink, write it as a 
directory anyway */
+#ifndef WIN32
+                               if (S_ISLNK(statbuf.st_mode))
+#else
+                               if (pgwin32_is_junction(pathbuf))
+#endif
+                                       statbuf.st_mode = S_IFDIR | S_IRWXU;
                                _tarWriteHeader(pathbuf + basepathlen + 1, 
NULL, &statbuf);
+                       }
                        size += 512;            /* Size of the header just 
added */
                        continue;
                }
-- 
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