I was in need of backing up a lot of data in a hurry. I used rsync between the file server and a locally mounted USB drive, but for some reason the command kept failing. It had something to do with checksum calculation, but it may have had something to do with how hardware is set up, so I didn’t wish to go looking for the very root of the problem; I just needed to back things up.
I simply decided to repeat the rsync command when it failed, until it succeeded syncing all files. Here’s a simple example script to do this:
#!/bin/bash CMD="rsync -av --delete remote:/scrXX/dir /media/usb/storage" while : do echo $CMD ; $CMD ; if [ $? -eq 0 ]; then break; fi echo "... redo ..." ; done echo "Done." ;
The gist of the Bash trick is to use “$?”, which stores the return code of the last executed process.