summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-06-17 19:13:18 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-06-17 19:13:18 -0400
commit334c608f2cb791c08af9f7507f77b4ca61369248 (patch)
tree7e0489e09087c333955d3bfd9d727dad971ac2ea /doc/src
parent32e5768390fe7c10230a1d02d9ee026461a609a9 (diff)
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 the warning that used to be there about that, and instead leaving the impression that the command would work as desired on most Unixen. It doesn't. Try to rectify the damage by providing an example that is safe most everywhere, and then noting that you can try cp -i if you want but you'd better test that. In back-patching this to all supported branches, I also added an example command for Windows, which wasn't provided before 9.0.
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/backup.sgml25
1 files changed, 14 insertions, 11 deletions
diff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml
index b646c7c5987..cec8ff5fe2b 100644
--- a/doc/src/sgml/backup.sgml
+++ b/doc/src/sgml/backup.sgml
@@ -560,7 +560,8 @@ tar -cf backup.tar /usr/local/pgsql/data
character in the command. The simplest useful command is something
like:
<programlisting>
-archive_command = 'cp -i %p /mnt/server/archivedir/%f &lt;/dev/null'
+archive_command = 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' # Unix
+archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
</programlisting>
which will copy archivable WAL segments to the directory
<filename>/mnt/server/archivedir</>. (This is an example, not a
@@ -568,7 +569,7 @@ archive_command = 'cp -i %p /mnt/server/archivedir/%f &lt;/dev/null'
<literal>%p</> and <literal>%f</> parameters have been replaced,
the actual command executed might look like this:
<programlisting>
-cp -i pg_xlog/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065 &lt;/dev/null
+test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_xlog/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065
</programlisting>
A similar command will be generated for each new file to be archived.
</para>
@@ -597,17 +598,19 @@ cp -i pg_xlog/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900
preserve the integrity of your archive in case of administrator error
(such as sending the output of two different servers to the same archive
directory).
+ </para>
+
+ <para>
It is advisable to test your proposed archive command to ensure that it
indeed does not overwrite an existing file, <emphasis>and that it returns
- nonzero status in this case</>. We have found that <literal>cp -i</> does
- this correctly on some platforms but not others. If the chosen command
- does not itself handle this case correctly, you should add a command
- to test for pre-existence of the archive file. For example, something
- like:
-<programlisting>
-archive_command = 'test ! -f .../%f &amp;&amp; cp %p .../%f'
-</programlisting>
- works correctly on most Unix variants.
+ nonzero status in this case</>.
+ The example command above for Unix ensures this by including a separate
+ <command>test</> step. On some Unix platforms, <command>cp</> has
+ switches such as <option>-i</> that can be used to do the same thing
+ less verbosely, but you should not rely on these without verifying that
+ the right exit status is returned. (In particular, GNU <command>cp</>
+ will return status zero when <option>-i</> is used and the target file
+ already exists, which is <emphasis>not</> the desired behavior.)
</para>
<para>