Обсуждение: PITR on Win32 - Archive and Restore Command Strings

Поиск
Список
Период
Сортировка

PITR on Win32 - Archive and Restore Command Strings

От
markir@coretech.co.nz
Дата:
Given that I was doing a bit of testing on win32 anyway, I just couldn't help
myself...

There is a bit of a trap if using '%p' in archive_command - it has seperators
like '/' instead of '\', so does not work for some windows commands (like
'copy' for instance).

I had to put in the complete path for pg_xlog, e.g:

archive_command = 'copy c:\\databases\\pgdata\\pg_xlog\\%f
c:\\databases\\pgarchive\\%f'

and similarly during recovery, e.g:

restore_command = 'copy c:\\databases\\pgarchive\\%f
c:\\databases\\pgdata\\pg_xlog\\%f'


Is there a format that is equivalent to '%p' but outputs a windows style path?

regards

Mark

P.S : PITR itself worked perfectly, rolling forward 106 logs....


Re: PITR on Win32 - Archive and Restore Command Strings

От
Tom Lane
Дата:
markir@coretech.co.nz writes:
> There is a bit of a trap if using '%p' in archive_command - it has seperators
> like '/' instead of '\', so does not work for some windows commands (like
> 'copy' for instance).

I was under the impression that forward slashes would work fine, as long
as you used them consistently?

            regards, tom lane

Re: PITR on Win32 - Archive and Restore Command

От
Mark Kirkwood
Дата:
hmmm... I was under that impression too, and was a bit surprised when it
*seemed* not to....I will go and check again - just in case some user
error leaked in :-)

Tom Lane wrote:

>markir@coretech.co.nz writes:
>
>
>>There is a bit of a trap if using '%p' in archive_command - it has seperators
>>like '/' instead of '\', so does not work for some windows commands (like
>>'copy' for instance).
>>
>>
>
>I was under the impression that forward slashes would work fine, as long
>as you used them consistently?
>
>            regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 8: explain analyze is your friend
>
>

Re: PITR on Win32 - Archive and Restore Command

От
Andrew Dunstan
Дата:
Not if you pass it to the Windows shell via system() or popen() - then
forward slashed paths need to be quoted. It's only the libraries that
understand forward slashes as God intended.

cheers

andrew

Mark Kirkwood wrote:

> hmmm... I was under that impression too, and was a bit surprised when
> it *seemed* not to....I will go and check again - just in case some
> user error leaked in :-)
>
> Tom Lane wrote:
>
>> markir@coretech.co.nz writes:
>>
>>
>>> There is a bit of a trap if using '%p' in archive_command - it has
>>> seperators
>>> like '/' instead of '\', so does not work for some windows commands
>>> (like
>>> 'copy' for instance).
>>>
>>
>>
>> I was under the impression that forward slashes would work fine, as long
>> as you used them consistently?
>>
>

Re: PITR on Win32 - Archive and Restore

От
markir@coretech.co.nz
Дата:
I tried out Andrew's suggestion, to no avail - none of the archive_commands
below work:

archive_command = 'copy "%p" "c:/databases/pgarchive/%f"'
archive_command = 'copy \"%p\" \"c:/databases/pgarchive/%f\"'
archive_command = 'copy \\"%p\\" \\"c:/databases/pgarchive/%f\\"' # desperation
...

A bit more investigation reveals that copy is bit selective about when it will
accept quoted paths containing '/'.

This works:

cd c:\databases\pgdata\pg_xlog
copy 00000001000000000000006A "c:/databases/pgarchive/00000001000000000000006A"

This does not (unless your current directory is pg_xlog!):

copy "c:/databases/pgdata/pg_xlog/00000001000000000000006A"
"c:/databases/pgarchive/00000001000000000000006A"

I guess this is not so bad if it is *just* 'copy' with this behaviour. I might
try out winzip and see how I get on...

regards (with some puzzlement)

Mark


Quoting Andrew Dunstan <andrew@dunslane.net>:

>
> Not if you pass it to the Windows shell via system() or popen() - then
> forward slashed paths need to be quoted. It's only the libraries that
> understand forward slashes as God intended.



Re: PITR on Win32 - Archive and Restore

От
Andrew Dunstan
Дата:
Oh, yes, multiple quotes strings also cause problems :-(. You have no
idea how frustrating this was when I was writing initdb, and how hard it
was to find the problems.

The chdir solution might be best if we can do it, so that we only need
to quote the destination path.

cheers

andrew

markir@coretech.co.nz wrote:

>I tried out Andrew's suggestion, to no avail - none of the archive_commands
>below work:
>
>archive_command = 'copy "%p" "c:/databases/pgarchive/%f"'
>archive_command = 'copy \"%p\" \"c:/databases/pgarchive/%f\"'
>archive_command = 'copy \\"%p\\" \\"c:/databases/pgarchive/%f\\"' # desperation
>...
>
>A bit more investigation reveals that copy is bit selective about when it will
>accept quoted paths containing '/'.
>
>This works:
>
>cd c:\databases\pgdata\pg_xlog
>copy 00000001000000000000006A "c:/databases/pgarchive/00000001000000000000006A"
>
>This does not (unless your current directory is pg_xlog!):
>
>copy "c:/databases/pgdata/pg_xlog/00000001000000000000006A"
>"c:/databases/pgarchive/00000001000000000000006A"
>
>I guess this is not so bad if it is *just* 'copy' with this behaviour. I might
>try out winzip and see how I get on...
>
>regards (with some puzzlement)
>
>Mark
>
>
>Quoting Andrew Dunstan <andrew@dunslane.net>:
>
>
>
>>Not if you pass it to the Windows shell via system() or popen() - then
>>forward slashed paths need to be quoted. It's only the libraries that
>>understand forward slashes as God intended.
>>
>>
>
>
>
>

Re: PITR on Win32 - Archive and Restore

От
Bruce Momjian
Дата:
Andrew Dunstan wrote:
>
> Oh, yes, multiple quotes strings also cause problems :-(. You have no
> idea how frustrating this was when I was writing initdb, and how hard it
> was to find the problems.
>
> The chdir solution might be best if we can do it, so that we only need
> to quote the destination path.
>
> cheers
>
> andrew
>
> markir@coretech.co.nz wrote:
>
> >I tried out Andrew's suggestion, to no avail - none of the archive_commands
> >below work:
> >
> >archive_command = 'copy "%p" "c:/databases/pgarchive/%f"'
> >archive_command = 'copy \"%p\" \"c:/databases/pgarchive/%f\"'
> >archive_command = 'copy \\"%p\\" \\"c:/databases/pgarchive/%f\\"' # desperation
> >...

As I remember the fix was to use this:

    archive_command = '"copy "%p" "c:/databases/pgarchive/%f""'

Yes, that is one extra quote at the start and end of the string.  Would
you try that?

FYI, port.h has this:

    /*
     *  Win32 needs double quotes at the beginning and end of system()
     *  strings.  If not, it gets confused with multiple quoted strings.
     *  It also must use double-quotes around the executable name
     *  and any files used for redirection.  Other args can use single-quotes.
     *
     *  See the "Notes" section about quotes at:
     *      http://home.earthlink.net/~rlively/MANUALS/COMMANDS/C/CMD.HTM
     */
    #ifdef WIN32
    #define SYSTEMQUOTE "\""
    #else
    #define SYSTEMQUOTE ""
    #endif


--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: PITR on Win32 - Archive and Restore

От
markir@coretech.co.nz
Дата:
Using :

archive_command = '"copy "%p" "c:/databases/pgarchive/%f""'

I see this is the log:

LOG:  archive command ""copy
"c:/databases/pgdata/pg_xlog/000000010000000000000000"
"c:/databases/pgarchive/000000010000000000000000""" failed: return code 1
The system cannot find the file specified.

Looks like it is confused about what the executable is...

regards

Mark

Quoting Bruce Momjian <pgman@candle.pha.pa.us>:

> Andrew Dunstan wrote:
> >
> > Oh, yes, multiple quotes strings also cause problems :-(. You have no
> > idea how frustrating this was when I was writing initdb, and how hard it
> > was to find the problems.
> >
> > The chdir solution might be best if we can do it, so that we only need
> > to quote the destination path.
> >
> > cheers
> >
> > andrew
> >
> > markir@coretech.co.nz wrote:
> >
> > >I tried out Andrew's suggestion, to no avail - none of the
> archive_commands
> > >below work:
> > >
> > >archive_command = 'copy "%p" "c:/databases/pgarchive/%f"'
> > >archive_command = 'copy \"%p\" \"c:/databases/pgarchive/%f\"'
> > >archive_command = 'copy \\"%p\\" \\"c:/databases/pgarchive/%f\\"' #
> desperation
> > >...
>
> As I remember the fix was to use this:
>
>     archive_command = '"copy "%p" "c:/databases/pgarchive/%f""'
>
> Yes, that is one extra quote at the start and end of the string.  Would
> you try that?
>
> FYI, port.h has this:
>
>     /*
>      *  Win32 needs double quotes at the beginning and end of system()
>      *  strings.  If not, it gets confused with multiple quoted strings.
>      *  It also must use double-quotes around the executable name
>      *  and any files used for redirection.  Other args can use single-quotes.
>      *
>      *  See the "Notes" section about quotes at:
>      *      http://home.earthlink.net/~rlively/MANUALS/COMMANDS/C/CMD.HTM
>      */
>     #ifdef WIN32
>     #define SYSTEMQUOTE "\""
>     #else
>     #define SYSTEMQUOTE ""
>     #endif
>
>
> --
>   Bruce Momjian                        |  http://candle.pha.pa.us
>   pgman@candle.pha.pa.us               |  (610) 359-1001
>   +  If your life is a hard drive,     |  13 Roberts Road
>   +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
>





Re: PITR on Win32 - Archive and Restore

От
Bruce Momjian
Дата:
markir@coretech.co.nz wrote:
> Using :
>
> archive_command = '"copy "%p" "c:/databases/pgarchive/%f""'
>
> I see this is the log:
>
> LOG:  archive command ""copy
> "c:/databases/pgdata/pg_xlog/000000010000000000000000"
> "c:/databases/pgarchive/000000010000000000000000""" failed: return code 1
> The system cannot find the file specified.
>
> Looks like it is confused about what the executable is...

OK, I think I might see the cause.  Try this:

    archive_command = '""copy" "%p" "c:/databases/pgarchive/%f""'

In other words, quote the 'copy' command too.  Crazy --- yes.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: PITR on Win32 - Archive and Restore

От
Tom Lane
Дата:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> OK, I think I might see the cause.  Try this:
>     archive_command = '""copy" "%p" "c:/databases/pgarchive/%f""'
> In other words, quote the 'copy' command too.  Crazy --- yes.

Yikes.  If it's that hard to get it to work, maybe we should just
knuckle under and make %p convert / to \ under Windows :-(

(Microsoft cultural imperialism wins another round...)

However, just one question --- the Microsofties also like to put spaces
in path names.  How much quoting would be needed to make this command
string work in the face of spaces in %p, even if we did the backslash
thing?  If the answer is "nearly as much" then I'm not going to be
excited about backslashing.

            regards, tom lane

Re: PITR on Win32 - Archive and Restore

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > OK, I think I might see the cause.  Try this:
> >     archive_command = '""copy" "%p" "c:/databases/pgarchive/%f""'
> > In other words, quote the 'copy' command too.  Crazy --- yes.
>
> Yikes.  If it's that hard to get it to work, maybe we should just
> knuckle under and make %p convert / to \ under Windows :-(
>
> (Microsoft cultural imperialism wins another round...)
>
> However, just one question --- the Microsofties also like to put spaces
> in path names.  How much quoting would be needed to make this command
> string work in the face of spaces in %p, even if we did the backslash
> thing?  If the answer is "nearly as much" then I'm not going to be
> excited about backslashing.

For sure we have to have the quoting working for spaces in directory
names.  Lets see how the new suggestion works for him.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: PITR on Win32 - Archive and Restore

От
Mark Kirkwood
Дата:
I will try it out later this afternoon.

I am a bit delayed with a hardware problem... suspect bad ram or too hot
cpu, so have been swapping and changing bits all morning (running with
500Mhz + 256M instead of 700Mhz + 512M ... noticeably slower).

regards

Mark

Bruce Momjian wrote:

>Tom Lane wrote:
>
>
>>Bruce Momjian <pgman@candle.pha.pa.us> writes:
>>
>>
>>>OK, I think I might see the cause.  Try this:
>>>    archive_command = '""copy" "%p" "c:/databases/pgarchive/%f""'
>>>In other words, quote the 'copy' command too.  Crazy --- yes.
>>>
>>>
>>Yikes.  If it's that hard to get it to work, maybe we should just
>>knuckle under and make %p convert / to \ under Windows :-(
>>
>>(Microsoft cultural imperialism wins another round...)
>>
>>However, just one question --- the Microsofties also like to put spaces
>>in path names.  How much quoting would be needed to make this command
>>string work in the face of spaces in %p, even if we did the backslash
>>thing?  If the answer is "nearly as much" then I'm not going to be
>>excited about backslashing.
>>
>>
>
>For sure we have to have the quoting working for spaces in directory
>names.  Lets see how the new suggestion works for him.
>
>
>

Re: PITR on Win32 - Archive and Restore

От
markir@coretech.co.nz
Дата:
Well, it is really fighting us.....

This is the archive_command:

'""copy.exe" "%p" "c:/databases/pgarchive/%f""'

and this is the log:

LOG:  archive command """copy.exe"
"c:/databases/pgdata/pg_xlog/000000010000000000000007"
"c:/databases/pgarchive/000000010000000000000007""" failed: return code 1
'"copy.exe"' is not recognized as an internal or external command,
operable program or batch file.

(tried plain old '"copy"' too)

regards

Mark

Quoting Bruce Momjian <pgman@candle.pha.pa.us>:> Tom Lane wrote:
> > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > OK, I think I might see the cause.  Try this:
> > >     archive_command = '""copy" "%p" "c:/databases/pgarchive/%f""'
> > > In other words, quote the 'copy' command too.  Crazy --- yes.
> >
> > Yikes.  If it's that hard to get it to work, maybe we should just
> > knuckle under and make %p convert / to \ under Windows :-(
> >
> > (Microsoft cultural imperialism wins another round...)
> >
> > However, just one question --- the Microsofties also like to put spaces
> > in path names.  How much quoting would be needed to make this command
> > string work in the face of spaces in %p, even if we did the backslash
> > thing?  If the answer is "nearly as much" then I'm not going to be
> > excited about backslashing.
>
> For sure we have to have the quoting working for spaces in directory
> names.  Lets see how the new suggestion works for him.





Re: PITR on Win32 - Archive and Restore

От
"Christian Klemke"
Дата:
"Copy" is an internal command of the command line shell in Windows. There is
no separate executable for it.
Try "cmd.exe /C copy ...." insteads (see "cmd /?" for further options).

Regards,
Christian.


----- Original Message -----
From: <markir@coretech.co.nz>
To: "Bruce Momjian" <pgman@candle.pha.pa.us>
Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; "Andrew Dunstan" <andrew@dunslane.net>;
<pgsql-hackers-win32@postgresql.org>
Sent: Monday, August 09, 2004 7:37 AM
Subject: Re: [pgsql-hackers-win32] PITR on Win32 - Archive and Restore


> Well, it is really fighting us.....
>
> This is the archive_command:
>
> '""copy.exe" "%p" "c:/databases/pgarchive/%f""'
>
> and this is the log:
>
> LOG:  archive command """copy.exe"
> "c:/databases/pgdata/pg_xlog/000000010000000000000007"
> "c:/databases/pgarchive/000000010000000000000007""" failed: return code 1
> '"copy.exe"' is not recognized as an internal or external command,
> operable program or batch file.
>
> (tried plain old '"copy"' too)
>
> regards
>
> Mark
>
> Quoting Bruce Momjian <pgman@candle.pha.pa.us>:> Tom Lane wrote:
> > > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > > OK, I think I might see the cause.  Try this:
> > > > archive_command = '""copy" "%p" "c:/databases/pgarchive/%f""'
> > > > In other words, quote the 'copy' command too.  Crazy --- yes.
> > >
> > > Yikes.  If it's that hard to get it to work, maybe we should just
> > > knuckle under and make %p convert / to \ under Windows :-(
> > >
> > > (Microsoft cultural imperialism wins another round...)
> > >
> > > However, just one question --- the Microsofties also like to put
spaces
> > > in path names.  How much quoting would be needed to make this command
> > > string work in the face of spaces in %p, even if we did the backslash
> > > thing?  If the answer is "nearly as much" then I'm not going to be
> > > excited about backslashing.
> >
> > For sure we have to have the quoting working for spaces in directory
> > names.  Lets see how the new suggestion works for him.
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match



Re: PITR on Win32 - Archive and Restore

От
"Andrew Dunstan"
Дата:
> Well, it is really fighting us.....
>
> This is the archive_command:
>
> '""copy.exe" "%p" "c:/databases/pgarchive/%f""'
>
> and this is the log:
>
> LOG:  archive command """copy.exe"
> "c:/databases/pgdata/pg_xlog/000000010000000000000007"
> "c:/databases/pgarchive/000000010000000000000007""" failed: return code
> 1 '"copy.exe"' is not recognized as an internal or external command,
> operable program or batch file.
>
> (tried plain old '"copy"' too)
>

What happens with this archive command?:

'"copy "%p" "c:/databases/pgarchive/%f""'

cheers

andrew



Re: PITR on Win32 - Archive and Restore

От
markir@coretech.co.nz
Дата:
I *think* I have tried that one, but checked anyway:

The result is :

LOG:  archive command ""copy
"c:/databases/pgdata/pg_xlog/000000010000000000000000"
"c:/databases/pgarchive/000000010000000000000000""" failed: return code 1
The system cannot find the file specified.

I think this led us on to more bizzare pastures...

mark


Quoting Andrew Dunstan <andrew@dunslane.net>:

> > Well, it is really fighting us.....
> >
> > This is the archive_command:
> >
> > '""copy.exe" "%p" "c:/databases/pgarchive/%f""'
> >
> > and this is the log:
> >
> > LOG:  archive command """copy.exe"
> > "c:/databases/pgdata/pg_xlog/000000010000000000000007"
> > "c:/databases/pgarchive/000000010000000000000007""" failed: return code
> > 1 '"copy.exe"' is not recognized as an internal or external command,
> > operable program or batch file.
> >
> > (tried plain old '"copy"' too)
> >
>
> What happens with this archive command?:
>
> '"copy "%p" "c:/databases/pgarchive/%f""'
>
> cheers
>
> andrew
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html
>





Re: PITR on Win32 - Archive and Restore

От
"Christian Klemke"
Дата:
Question:
It is my understanding that this copy operation is initiated out of some
main program and not in a shell script, right ?
Then why don't you use one of the CopyFile or CopyFileEx API routines on
Win32 ? Sure, it will need some additional #ifdef clauses in the source
codes, but I think performance will be better and you can even include a
progress callback function. Besides, no child process needs to be created
and - best of all ! - this approach removes all file name escaping and
parsing issues because it will take source and destination parameters as
strings.
What do you think ?

Regards,
Christian.

----- Original Message -----
From: "Andrew Dunstan" <andrew@dunslane.net>
To: <markir@coretech.co.nz>
Cc: <pgsql-hackers-win32@postgresql.org>
Sent: Monday, August 09, 2004 9:36 AM
Subject: Re: [pgsql-hackers-win32] PITR on Win32 - Archive and Restore


> > Well, it is really fighting us.....
> >
> > This is the archive_command:
> >
> > '""copy.exe" "%p" "c:/databases/pgarchive/%f""'
> >
> > and this is the log:
> >
> > LOG:  archive command """copy.exe"
> > "c:/databases/pgdata/pg_xlog/000000010000000000000007"
> > "c:/databases/pgarchive/000000010000000000000007""" failed: return code
> > 1 '"copy.exe"' is not recognized as an internal or external command,
> > operable program or batch file.
> >
> > (tried plain old '"copy"' too)
> >
>
> What happens with this archive command?:
>
> '"copy "%p" "c:/databases/pgarchive/%f""'
>
> cheers
>
> andrew
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html
>



Re: PITR on Win32 - Archive and Restore

От
markir@coretech.co.nz
Дата:
Good suggestion, got me thinking-

Trying out stuff on the command line seems to show a general "unwillingness" to
work with forward slashed names at all:


C:\>cmd /c copy "c:/databases/pgdata/
pg_xlog/000000010000000000000000"  "c:/databases/pgarchive/000000010000000000000
000"
The system cannot find the file specified.
        0 file(s) copied.

C:\>cmd /c "copy" "c:/databases/pgdata/pg_xlog/000000010000000000000000"  "c:/da
tabases/pgarchive/000000010000000000000000"
'copy" "c:' is not recognized as an internal or external command,
operable program or batch file.

C:\>cmd /c "copy "c:/databases/pgdata/pg_xlog/000000010000000000000000"  "c:/dat
abases/pgarchive/000000010000000000000000""
The system cannot find the file specified.
        0 file(s) copied.

C:\>cmd /c ""copy" "c:/databases/pgdata/pg_xlog/000000010000000000000000"  "c:/d
atabases/pgarchive/000000010000000000000000""
'"copy"' is not recognized as an internal or external command,
operable program or batch file.

whereas of course :

C:\>cmd /c copy c:\databases\pgdata\pg_xlog\000000010000000000000000  c:\databa
es\pgarchive\000000010000000000000000
        1 file(s) copied.


Quoting Christian Klemke <Christian.Klemke@t-online.de>:

> "Copy" is an internal command of the command line shell in Windows. There is
> no separate executable for it.
> Try "cmd.exe /C copy ...." insteads (see "cmd /?" for further options).
>
> Regards,
> Christian.
>




Re: PITR on Win32 - Archive and Restore

От
"Gary Doades"
Дата:
On 9 Aug 2004 at 20:12, markir@coretech.co.nz wrote:

> I *think* I have tried that one, but checked anyway:
>
> The result is :
>
> LOG:  archive command ""copy
> "c:/databases/pgdata/pg_xlog/000000010000000000000000"
> "c:/databases/pgarchive/000000010000000000000000""" failed: return code 1
> The system cannot find the file specified.
>
> I think this led us on to more bizzare pastures...
>

The problem here is that "Copy" is not an external command (as it
says), but it is built into the "shell" (cmd.exe). To use copy you would
have to run cmd.exe and make the copy command the first parameter
after the /C switch.

It's much better to use "xcopy" anyway, which *is* an external command
and can be run with a string similar to the one use are using now.

Cheers,
Gary.


Re: PITR on Win32 - Archive and Restore

От
Tom Lane
Дата:
markir@coretech.co.nz writes:
> Trying out stuff on the command line seems to show a general "unwillingness" to
> work with forward slashed names at all:

Yeah, I think it may only be the POSIX library routines that are really
forward-slash friendly.

As I said before, I'm willing to #ifdef the code so that the string
substituted for %p converts all / to \ on Windows.  What I'd like to
know is whether that's enough to solve the problems, particularly in
face of spaces in the path, or whether we'll still be in quoting hell.

            regards, tom lane

Re: PITR on Win32 - Archive and Restore

От
Andrew Dunstan
Дата:

Tom Lane wrote:

>markir@coretech.co.nz writes:
>
>
>>Trying out stuff on the command line seems to show a general "unwillingness" to
>>work with forward slashed names at all:
>>
>>
>
>Yeah, I think it may only be the POSIX library routines that are really
>forward-slash friendly.
>
>As I said before, I'm willing to #ifdef the code so that the string
>substituted for %p converts all / to \ on Windows.  What I'd like to
>know is whether that's enough to solve the problems, particularly in
>face of spaces in the path, or whether we'll still be in quoting hell.
>
>
>

Names with spaces will need to be quoted :-(

The good news is that we don't seem to need as many quotes as Bruce
suggested. See my earlier email.

cheers

andrew

Re: PITR on Win32 - Archive and Restore

От
Tom Lane
Дата:
Andrew Dunstan <andrew@dunslane.net> writes:
> Tom Lane wrote:
>> As I said before, I'm willing to #ifdef the code so that the string
>> substituted for %p converts all / to \ on Windows.  What I'd like to
>> know is whether that's enough to solve the problems, particularly in
>> face of spaces in the path, or whether we'll still be in quoting hell.

> Names with spaces will need to be quoted :-(

But does that have to be done in the code, or will
    archive_command = 'copy "%p" ...'
work?

Strictly speaking, people probably ought to use something like
    archive_command = 'cp "%p" ...'
on Unix too, so if this is what it takes on Windows I'm satisfied.
Just wondering about what other gotchas Redmond has prepared for us...

            regards, tom lane

Re: PITR on Win32 - Archive and Restore

От
Andrew Dunstan
Дата:

Tom Lane wrote:

>Andrew Dunstan <andrew@dunslane.net> writes:
>
>
>>Tom Lane wrote:
>>
>>
>>>As I said before, I'm willing to #ifdef the code so that the string
>>>substituted for %p converts all / to \ on Windows.  What I'd like to
>>>know is whether that's enough to solve the problems, particularly in
>>>face of spaces in the path, or whether we'll still be in quoting hell.
>>>
>>>
>
>
>
>>Names with spaces will need to be quoted :-(
>>
>>
>
>But does that have to be done in the code, or will
>    archive_command = 'copy "%p" ...'
>work?
>
>

That should work just fine (or with xcopy).

>Strictly speaking, people probably ought to use something like
>    archive_command = 'cp "%p" ...'
>on Unix too, so if this is what it takes on Windows I'm satisfied.
>Just wondering about what other gotchas Redmond has prepared for us...
>
>
>
>

Yes, it's just that Unix people (or at least those of us who are
professionals) usually have more sense that to put spaces in file names ...

cheers

andrew

Re: PITR on Win32 - Archive and Restore

От
Tom Lane
Дата:
Andrew Dunstan <andrew@dunslane.net> writes:
> Tom Lane wrote:
>> But does that have to be done in the code, or will
>> archive_command = 'copy "%p" ...'
>> work?

> That should work just fine (or with xcopy).

Okay, I'll change %p to emit \ on Windows, and we'll see where that
takes us.

            regards, tom lane

Re: PITR on Win32 - Archive and Restore

От
Tom Lane
Дата:
> Okay, I'll change %p to emit \ on Windows, and we'll see where that
> takes us.

I've applied the attached patch, in case anyone is in a big hurry to try
it.

            regards, tom lane


Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/access/transam/xlog.c,v
retrieving revision 1.157
diff -c -r1.157 xlog.c
*** src/backend/access/transam/xlog.c    8 Aug 2004 03:22:08 -0000    1.157
--- src/backend/access/transam/xlog.c    9 Aug 2004 16:23:51 -0000
***************
*** 1962,1968 ****
--- 1962,1978 ----
                      /* %p: full path of target file */
                      sp++;
                      StrNCpy(dp, xlogpath, endp-dp);
+ #ifndef WIN32
                      dp += strlen(dp);
+ #else
+                     /* On Windows, change / to \ in the substituted path */
+                     while (*dp)
+                     {
+                         if (*dp == '/')
+                             *dp = '\\';
+                         dp++;
+                     }
+ #endif
                      break;
                  case 'f':
                      /* %f: filename of desired file */
Index: src/backend/postmaster/pgarch.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/postmaster/pgarch.c,v
retrieving revision 1.5
diff -c -r1.5 pgarch.c
*** src/backend/postmaster/pgarch.c    5 Aug 2004 23:32:10 -0000    1.5
--- src/backend/postmaster/pgarch.c    9 Aug 2004 16:23:51 -0000
***************
*** 436,442 ****
--- 436,452 ----
                      /* %p: full path of source file */
                      sp++;
                      StrNCpy(dp, pathname, endp-dp);
+ #ifndef WIN32
                      dp += strlen(dp);
+ #else
+                     /* On Windows, change / to \ in the substituted path */
+                     while (*dp)
+                     {
+                         if (*dp == '/')
+                             *dp = '\\';
+                         dp++;
+                     }
+ #endif
                      break;
                  case 'f':
                      /* %f: filename of source file */

Re: PITR on Win32 - Archive and Restore

От
Mark Kirkwood
Дата:
The only down side is now we have 2 classes of parameters in
postgresql.conf:

- ones that accept forward slash names (log_directory)
- ones that only work with backslashes (archive_command)

The other option was to consider making the archiver change working
directory to pg_xlog, then the
forward slashed names will work (going by experiments with copy).

regards

Mark

Tom Lane wrote:

>Andrew Dunstan <andrew@dunslane.net> writes:
>
>
>>Tom Lane wrote:
>>
>>
>>>But does that have to be done in the code, or will
>>>archive_command = 'copy "%p" ...'
>>>work?
>>>
>>>
>
>
>
>>That should work just fine (or with xcopy).
>>
>>
>
>Okay, I'll change %p to emit \ on Windows, and we'll see where that
>takes us.
>
>            regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: Have you searched our list archives?
>
>               http://archives.postgresql.org
>
>

Re: PITR on Win32 - Archive and Restore

От
"Andrew Dunstan"
Дата:
Mark Kirkwood said:
> The only down side is now we have 2 classes of parameters in
> postgresql.conf:
>
> - ones that accept forward slash names (log_directory)
> - ones that only work with backslashes (archive_command)
>

Without looking at it closely, ISTM we should force canonicalisation of the
logdir name, so that on Windows it would accept backslahes. After all,
initdb and pg_ctl (to name but two I have knowledge of) accept backslashes.

cheers

andrew




Re: PITR on Win32 - Archive and Restore

От
Bruce Momjian
Дата:
I have gotten confused by this.  Does COPY work with quoted paths only
if we use forward slashes, or was this fix just for the slash issue and
not spaces?

---------------------------------------------------------------------------

Tom Lane wrote:
> > Okay, I'll change %p to emit \ on Windows, and we'll see where that
> > takes us.
>
> I've applied the attached patch, in case anyone is in a big hurry to try
> it.
>
>             regards, tom lane
>
>
> Index: src/backend/access/transam/xlog.c
> ===================================================================
> RCS file: /cvsroot/pgsql-server/src/backend/access/transam/xlog.c,v
> retrieving revision 1.157
> diff -c -r1.157 xlog.c
> *** src/backend/access/transam/xlog.c    8 Aug 2004 03:22:08 -0000    1.157
> --- src/backend/access/transam/xlog.c    9 Aug 2004 16:23:51 -0000
> ***************
> *** 1962,1968 ****
> --- 1962,1978 ----
>                       /* %p: full path of target file */
>                       sp++;
>                       StrNCpy(dp, xlogpath, endp-dp);
> + #ifndef WIN32
>                       dp += strlen(dp);
> + #else
> +                     /* On Windows, change / to \ in the substituted path */
> +                     while (*dp)
> +                     {
> +                         if (*dp == '/')
> +                             *dp = '\\';
> +                         dp++;
> +                     }
> + #endif
>                       break;
>                   case 'f':
>                       /* %f: filename of desired file */
> Index: src/backend/postmaster/pgarch.c
> ===================================================================
> RCS file: /cvsroot/pgsql-server/src/backend/postmaster/pgarch.c,v
> retrieving revision 1.5
> diff -c -r1.5 pgarch.c
> *** src/backend/postmaster/pgarch.c    5 Aug 2004 23:32:10 -0000    1.5
> --- src/backend/postmaster/pgarch.c    9 Aug 2004 16:23:51 -0000
> ***************
> *** 436,442 ****
> --- 436,452 ----
>                       /* %p: full path of source file */
>                       sp++;
>                       StrNCpy(dp, pathname, endp-dp);
> + #ifndef WIN32
>                       dp += strlen(dp);
> + #else
> +                     /* On Windows, change / to \ in the substituted path */
> +                     while (*dp)
> +                     {
> +                         if (*dp == '/')
> +                             *dp = '\\';
> +                         dp++;
> +                     }
> + #endif
>                       break;
>                   case 'f':
>                       /* %f: filename of source file */
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073