Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T5Pxy-0003Sf-SQ for pgsql-docs@postgresql.org; Sat, 25 Aug 2012 23:40:35 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T5Pxt-0003wR-Sb for pgsql-docs@postgresql.org; Sat, 25 Aug 2012 23:40:33 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1T5Pxq-0007H4-DM; Sat, 25 Aug 2012 19:40:26 -0400 Date: Sat, 25 Aug 2012 19:40:26 -0400 From: Bruce Momjian To: Peter Eisentraut Cc: Josh Kupershmidt , Greg Smith , Euler Taveira de Oliveira , pgsql-docs@postgresql.org Subject: Re: somewhat wrong archive_command example Message-ID: <20120825234026.GG10814@momjian.us> References: <1316524671.9044.12.camel@fsopti579.F-Secure.com> <4E794FB5.80400@2ndQuadrant.com> <1316613536.14119.6.camel@fsopti579.F-Secure.com> <4E7A6D0D.4060106@2ndQuadrant.com> <4E7A887F.8010908@timbira.com> <20120816011347.GF8353@momjian.us> <502EA0D0.10004@gmx.net> <20120825230755.GE10814@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="FkmkrVfFsRoUs1wW" Content-Disposition: inline In-Reply-To: <20120825230755.GE10814@momjian.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201208/43 X-Sequence-Number: 7436 --FkmkrVfFsRoUs1wW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Aug 25, 2012 at 07:07:55PM -0400, Bruce Momjian wrote: > > >I have made all the suggestions posted and would like to add the > > >attached script to our documentation as a simple example. > > > > Btw., is anyone else concerned about using plain cp for this? If > > the cp fails half-way, it leaves a partial file around, but > > subsequent file existence checks will find the file OK and skip it. > > > > I have occasionally used some combination of mktemp + cp + mv, which > > seems to work around this problem. > > I am unclear why the script returns success if the file already exists > --- seems if the file exists, we should throw an error, like we have > always done with cp -i < /dev/null. > > Updated version attached. > > Another option in this case would be to re-issue the copy. Sorry, proper attached file this time. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --FkmkrVfFsRoUs1wW Content-Type: application/x-sh Content-Disposition: attachment; filename="local_backup_script.sh" Content-Transfer-Encoding: quoted-printable #!/bin/sh=0A=0A# archive_command script for Standalone Hot Backup=0A=0A# SE= T THIS VARIABLE TO YOUR ARCHIVE DIRECTORY=0AARCHIVE=3D"/mnt/pg_archive"=0A= =0AFULLPATH=3D"$1"=0AFILE=3D"$2"=0A=0Aif [ ! -d "$ARCHIVE" ] ; then=0A ech= o "$0: ERROR: Archive directory does not exist" 1>&2=0A exit 1=0Afi=0A= =0Aif [ -f "$ARCHIVE/$FILE" ] ; then=0A echo "$0: ERROR: Archive file $F= ILE already exists in archive directory" 1>&2=0A exit 1=0Afi=0A=0Acp "$FUL= LPATH" "$ARCHIVE/$FILE"=0A=0ARET=3D"$?"=0A=0Aif [ "$RET" -ne 0 ] ; then=0A = echo "$0: ERROR: Archive copy of $FILE failed with return code $RET" 1>&= 2=0Afi=0A=0Aexit $RET=0A --FkmkrVfFsRoUs1wW--