I apologise for this post. I left a small part of code out for what I thought was brevity but the extra removed line was the cause of the problem. The full relevant code is
Code:
localArchive=/tmp/pgDspaceChara
remoteMachine="targetMachine.mycompany.com.au"
su --shell=/bin/bash --session-command="/usr/bin/pg_dumpall --clean --oids" postgres > ${localArchive}&
rsync -abvz ${localArchive} root@${remoteMachine}:/data/
The postgres dump has a background ampersand on the end which should not be there.
Before the dump process can complete, rsync attempts to run and the file transfer is incomplete. Hence the reason why sometimes there was a partial transfer.
By the time I checked the file in /tmp the dump completed and the /tmp file looked okay and also thne rsync tried from the command line would work. Running the script again starts rewriting the file and gives the appearance that it works in the command line but not the script.
Thanks for your suggestion anyway they were helpful. Thanx