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

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

Re: PITR on Win32 - Archive and Restore

От
Bruce Momjian
Дата:
OK, next question.  Why does this work when compiled in MinGW and run
from CMD.EXE:

    # cat x.c
    #include <stdio.h>

    main()
    {
            system("copy \"c:/msys/1.0/home/bruce momjian/a b\" \"c:/msys/1.0/home/bruce momjian/c d\"");
    }
    # gcc -o x x.c
    # ./x
            1 file(s) copied.

    C:\msys\1.0\home\Bruce Momjian>x
            1 file(s) copied.

The path has forward slashes and spaces.

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

markir@coretech.co.nz wrote:
> Funny thing is, now that the "%p" is silently using '\', the "target" path can
> use '/':
>
> e.g :
>
> archive_command = 'copy "%p" "c:/databases/pgarchive/%f"'
>
> *now* works fine. The next interesting question will be "can I use '/' in the
> restore_command too?". I will have a muddle around with it.
>
> regards
>
> Mark
>
> Quoting markir@coretech.co.nz:
>
> > I agree, the approach seems quite nice.
> >
> > I gave the lastest cvs a go  - which is probably cvs as of about 2 hours ago,
> > as
> > a mingw build takes 55 minutes on this machine (compare to 6 minutes when
> > booted into Freebsd... ah well..)
> >
> >
> > Initially tried :
> >
> > archive_command = 'copy "%p" "c:\databases\pgarchive\%f"'
> >
> > But saw errors in the log about "c:databasespgarchive00000..."
> >
> > Looks like '\' needs to be escaped, confirmed this with :
> >
> >
> > archive_command = 'copy "%p" "c:\\databases\\pgarchive\\%f"'
> >
> > Which worked fine. However, it would be nice if the '\' inside the '"' were
> > 'auto-escaped' somehow, as I suspect Mr 'used-windows-all-my-life' will find
> > the current behaviour counter-intuitive.
> >
> > Otherwise looks good
> >
> > Mark
> >
> >
> >
> > Quoting Andrew Dunstan <andrew@dunslane.net>:
> >
> > > Tom Lane said:
> > > > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > >> 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?
> > > >
> > > > This only fixes the slash issue.  If your database path includes spaces
> > > > you'll still need to put quotes in the archive_command, but it
> > > > shouldn't be any worse than
> > > >     archive_command = 'copy "%p" "c:\someplace\%f"'
> > > >
> > > > I'd appreciate confirmation though from some win32 users that the above
> > > > indeed works.
> > > >
> > >
> > > That's what my experimentation showed, although I worked with a tiny test.c
> > > file rather than the archive command. I think this is the right solution -
> > > the user should put the quotes in, not postgres.
> > >
> > > cheers
> > >
> > > andrew
> > >
> > >
> > >
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> > >
> >
> >
> >
> >
>
>
>
>

--
  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

От
"Andrew Dunstan"
Дата:
Bruce Momjian said:
>
> OK, next question.  Why does this work when compiled in MinGW and run
> from CMD.EXE:
>
>     # cat x.c
>     #include <stdio.h>
>
>     main()
>     {
>             system("copy \"c:/msys/1.0/home/bruce momjian/a b\"
>             \"c:/msys/1.0/home/bruce momjian/c d\"");
>     }
>     # gcc -o x x.c
>     # ./x
>             1 file(s) copied.
>
>     C:\msys\1.0\home\Bruce Momjian>x
>             1 file(s) copied.
>
> The path has forward slashes and spaces.
>
>

on XP Pro a similar test gives me:

C:\msys\1.0\home\adunstan>copytry
copy "c:/tmp/a b" "c:/tmp/c d"
The system cannot find the file specified.
        0 file(s) copied.

C:\msys\1.0\home\adunstan>dir c:\tmp
 Volume in drive C has no label.
 Volume Serial Number is D899-679E

 Directory of c:\tmp

08/10/2004  10:36 PM    <DIR>          .
08/10/2004  10:36 PM    <DIR>          ..
06/14/2004  05:33 PM             9,244 a b
06/14/2004  05:33 PM             9,244 INSTALL.LOG
               2 File(s)         18,488 bytes
               2 Dir(s)  51,230,498,816 bytes free

but with backslashes, I get:

C:\msys\1.0\home\adunstan>copytry
copy "c:\tmp\a b" "c:\tmp\c d"
        1 file(s) copied.

and with backslashes in the source only I get:

C:\msys\1.0\home\adunstan>copytry
copy "c:\tmp\a b" "c:/tmp/c d"
        1 file(s) copied.

go figure ...

cheers

andrew





Re: PITR on Win32 - Archive and Restore

От
"Gary Doades"
Дата:
On 10 Aug 2004 at 22:59, Andrew Dunstan wrote:

>
> C:\msys\1.0\home\adunstan>copytry
> copy "c:\tmp\a b" "c:\tmp\c d"
>         1 file(s) copied.
>
> and with backslashes in the source only I get:
>
> C:\msys\1.0\home\adunstan>copytry
> copy "c:\tmp\a b" "c:/tmp/c d"
>         1 file(s) copied.
>
> go figure ...

According to MSDN: "forward slashes work fine in most cases", the
usual non-commital stuff from MS

One thing is for certain, if you want to use forward slashes (/) then you
will *have* to quote them. The (/) on windows (DOS!) is also a switch
delimiter. If you don't quote paths containing (/) then confusion will be
abundant.

Also if you want to use backslash (\) then you will need to escape it if it
is a "C" string.

Sadly I'm not convinced there is a single solution fits all if you want to
use shell (system()) commands under Windows. It just contains so
much historical baggage (DOS) that you can't be 100% sure that it will
work in all cases. Just because a small set of tests using the copy
command work, I'm not sure other commands will!

If you need stuff that is critical to the operation of Postgres that you
need to work whatever, then I say some small utilities (copy.exe?) that
work in a predicatable way need to be written to ensure this.

For non-critcal stuff documentation is needed to tell the user that they
may need to experiment with command formats.

Cheers,
Gary.