If you're just trying to copy a directory structure over a network I've used rcmd (on UNIX) like...
rcmd -l user host "(cd /usr/rob ; find . -print -depth | cpio -ocdu) " | (cd /usr/somewhere | cpio -icvduAm)
Regards, Rob.
On 20 Jan 2005, at 5:06 pm, Richard Lewis wrote:
Hello ALUG,
I'm trying to write a bash script to mirror some files on my server to another machine (to be run periodically, not a dynamic mirror).
First it creates a file which contains the full path of all the files that need to be copied (they are in lots of different directories) separated by newlines (I'd like to keep this aspect of the script as it is also used to create an ISO to backup to DVD sometimes).
Next I want to copy all the files in the list to the remote computer. (I've been reading up on scp and have managed to add my key the remote machine so that the script isn't interrupted by password prompts.) The problem I've got is that each item in the list is the name of a regular file including its path and scp won't allow me to copy to the remote machine into a path which doesn't exist:
$ROOT=/var/server-mirror ..... for f in `cat FILES` do scp $f $USER@$HOST:$ROOT/$f done
[where each $f will be the absolute path of the local file, e.g. '/var/www/index.html' which should copy to '/var/server-mirror/var/www/index.html' on the remote machine]
The -r switch, of course, isn't the solution because that only applies to directories at the local end and still doesn't allow you to copy to non-existant directories at the remote end. I suppose what I need is a sort of 'rmkdir' with the -p switch:
rmkdir -p $HOST:$ROOT/`dirname $f`
Any ideas?
Cheers, Richard
PS. Theres no need to use scp if a solution exists using something else.... -- Richard Lewis richardlewis@fastmail.co.uk