Is it possible for rsync to rename its destination folder after successful run. So that I can always make sure the proper folder name always has a successful and complete backup?


rsync to folder /backup/incomplete-2017-02-26 and after it finished synching to rename it to /backup/2017-02-26


I need this for either local folders or remote folders.


Just use the return value of rsync - it will return 0 upon successful completion:

if rsync  -av source dest ; then 
   mv folder
   echo "Something went wrong"

The exit code is also available in the variable $? right after the command runs - beware, this will be overwritten by the next command.

  • The rsync destination could also be a remote address, so this won't work for all cases. I added that to the initial question to make it more clear – cytopia Feb 26 '17 at 18:13
  • Why wouldn't this work for remote locations? If the transfer fails, rsync will exit with something else then 0. If it suceeds, you can do something like ssh user@host mv .... – Sven Feb 26 '17 at 18:55
  • But how would the script know if rsync was done to a local path or an remote one? it should either be doing mv or ssh ... mv. – cytopia Feb 26 '17 at 19:05
  • You could use flags for the script or you could look into the command (e.g. if the target contains a :/ it is most likely remote) – Sven Feb 26 '17 at 19:22
  • Just as a small addition: rsync -av source dest && mv folder may work as a shorter version of the above if (won't print out an error message though). – rvs Feb 26 '17 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.