So I've recently written a bash script for rsync, to sync an usb hard drive to a folder on my server. A day or two after running the script I notice some files are missing from the source folder.

Could someone be a darling and check my script to see if it would have deleted files from the source? (server folder) or if it is just deleting files from the destination (usb hdd) that are no longer on the source (as I meant for it to do).

# rsync folders


sudo rsync -h -v -r -P -t --delete-after --exclude="*/*/*/THUM" --exclude="*result*" --exclude=".DS_Store" --exclude="._.DS_Store" --include="*.pdf" --include="*.PDF" --include="*.jpg" --include="*.JPG" --include="*.tif" --include="*.TIF" --include="*.xhtml" --include="*.XHTML" --include="*.xml" --include="*.XML" $SOURCEDIR $DESTDIR

Hopefully it wasn't down to the script (I mean it worked in testing). Any help would be awesome =] Pleases and thank yous!

  • What files are missing? – waltinator Jul 29 '16 at 14:31
  • Some .tif and .pdf files are missing from the server/source. – Pete Duggan Jul 29 '16 at 14:36

The only rsync option you have used that can potentially remove file is --delete-after but that deletes files from the destination, not from the source. This is true for all --delete options of rsync. The only option to remove files from source is --remove-source-files.

So your rsync command should not remove any file from source.

On a different note, the -h option is for help, which is doing nothing in your case, also you should look at the -a (--archive) option as you are already using most of the options it includes.

Also as you have many --include patterns, you should rather define the patterns in a file and use --include-from option instead to make the command line more readable and easily maintainable.

  • Thanks for the knowledge =] much appreciated (sorry about the late response :/ ) – Pete Duggan Sep 2 '16 at 9:15

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.