Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae7fc61

Browse files
committed
Don't use "cp -i" in the example WAL archive_command.
This is a dangerous example to provide because on machines with GNU cp,it will silently do the wrong thing and risk archive corruption. Worse,during the 9.0 cycle somebody "improved" the discussion by removing thewarning that used to be there about that, and instead leaving theimpression that the command would work as desired on most Unixen.It doesn't. Try to rectify the damage by providing an example that is safemost everywhere, and then noting that you can try cp -i if you want butyou'd better test that.In back-patching this to all supported branches, I also added an examplecommand for Windows, which wasn't provided before 9.0.
1 parent7975f2b commitae7fc61

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

‎doc/src/sgml/backup.sgml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ tar -cf backup.tar /usr/local/pgsql/data
577577
character in the command. The simplest useful command is something
578578
like:
579579
<programlisting>
580-
archive_command = 'cp -i %p/mnt/server/archivedir/%f &lt;/dev/null' # Unix
580+
archive_command = 'test ! -f/mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' # Unix
581581
archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
582582
</programlisting>
583583
which will copy archivable WAL segments to the directory
@@ -586,7 +586,7 @@ archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
586586
<literal>%p</> and <literal>%f</> parameters have been replaced,
587587
the actual command executed might look like this:
588588
<programlisting>
589-
cp -i pg_xlog/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065 &lt;/dev/null
589+
test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_xlog/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065
590590
</programlisting>
591591
A similar command will be generated for each new file to be archived.
592592
</para>
@@ -615,18 +615,19 @@ cp -i pg_xlog/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900
615615
preserve the integrity of your archive in case of administrator error
616616
(such as sending the output of two different servers to the same archive
617617
directory).
618+
</para>
619+
620+
<para>
618621
It is advisable to test your proposed archive command to ensure that it
619622
indeed does not overwrite an existing file, <emphasis>and that it returns
620-
nonzero status in this case</>. On many Unix platforms, <command>cp
621-
-i</> causes copy to prompt before overwriting a file, and
622-
<literal>&lt; /dev/null</> causes the prompt (and overwriting) to
623-
fail. If your platform does not support this behavior, you should
624-
add a command to test for the existence of the archive file. For
625-
example, something like:
626-
<programlisting>
627-
archive_command = 'test ! -f /mnt/server/archivedir/%f &amp;&amp; cp %p /mnt/server/archivedir/%f'
628-
</programlisting>
629-
works correctly on most Unix variants.
623+
nonzero status in this case</>.
624+
The example command above for Unix ensures this by including a separate
625+
<command>test</> step. On some Unix platforms, <command>cp</> has
626+
switches such as <option>-i</> that can be used to do the same thing
627+
less verbosely, but you should not rely on these without verifying that
628+
the right exit status is returned. (In particular, GNU <command>cp</>
629+
will return status zero when <option>-i</> is used and the target file
630+
already exists, which is <emphasis>not</> the desired behavior.)
630631
</para>
631632

632633
<para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp