Ubuntu – Rsync behavior in a cron script

backupbashcronnfsrsync

I have an nfs device that creates checkpoint (backups) everyday. I want to use Rsync to copy these checkpoints to another device (Drobo connected via iSCSI). So I've run the script on a single nfs share and it works nicely. Here are a couple concerns I have that will take too long to experiment with multiple times.

  1. There are multiple shares to back up, and I would like to loop through them and run the script over each one. How will this work with Rsync? Will the Rsync job start and then loop again and run a second and third and fourth Rsync job simultaneously, or will Rsync wait for the job to finish before ending and restarting the loop? Maybe I just need to put some check in the loop to not restart until Rsync is done.

  2. Referring to that last sentence; what does Rsync return that I could use to report if there was an error or continue the loop if all went well?

  3. The checkpoints created by the NFS device are named based on the date. Rsync is unpacking the .ckpt* file into a statically named directory. Since the source is a different directory but the files inside are the same, and the target is named the same, will Rsync still only copy the differences?

this is the rsync job:
rsync -az $NEWCHKPT/* /drobo/bak.${share}/${share}_daily

I know this is post is asking alot. Any advice is greatly appreciated.

Best Answer

  1. Depends on how you write the loop; unless you background the rsync commands with the & symbol, the rsync commands will run in sequence.

  2. rsync will return a useful exit status. These are listed in rsync's manual page. man rsync | less '+/^EXIT VALUE'. You have to decide whether you want to abort the whole script when one fails, or attempt to run the others, then provide an error summary at the end for the ones that failed.

  3. rsync has various ways to decide whether to copy a file or not. The default is to check the size and last modification time of the source and destination files. If both match, it skips copying that file. That's usually good enough.

Related Question