Rsync –files-from equivalent

rsync

I'm attempting to back some stuff up from a server that runs an old version of rsync – for various reasons I can't just upgrade the software.

Usually, I'd use –files-from and give a list of files and directories to back up, but this version of rsync doesn't have that switch. Is there a way, with other switches, to make an older rsync behave the same way?

I've tried a combination of –include-from= –exclude=* but that looks to be insufficiently recursive (eg. /etc/* only backs up things directly below /etc).

Best Answer

I suspect that xargs is your friend in this instance.

Completely untested:

 # cat file | xargs -IREPLACE rsync -v REPLACE server:/path

xargs will take data from stdin and add it to the commandline one parameter per input line until it fills the command line length, and then runs a separate command until all the input lines have been used up. This will mean that rsync could well run more than once. This shouldn't be a problem in this case, but could be with other commands.

Usually xargs just sticks the arguments on the end of the line, but with rsync you'd want to have the destination last, so we use the -I option to replace a string with the arguments. (This is the bit that's untested). I'm also a little unsure what rsync will do with the paths, so please test this carefully before using it in anger.

If you do have a problem with xargs, you could use something like:

for i in $(cat file); do rsync -v $i server:/path; done

If your file is larger, you probably want to use a while/read loop instead. This will be much slower as it will do a single file at a time.

Related Topic