Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Problems with rsync scripting

I'm having a problem scripting rsync since updating from Snow Leopard to Mavericks. I had an Applescript that would backup a USB thumb drive with rsync. It stopped working after the upgrade. The odd thing is that the exact same rsync command works from the command line. I re-wrote the backup script as a .sh file. Same problem. I can run the script from Textwrangler and it works. Running it from the file gives the same error.


The rsync command:

rsync -azv --ignore-existing --delete --exclude='.*' '/Volumes/No Name/' '/Users/scott/Documents/Documents/Backup_USB_Drive/Backup_New/'


The error:

building file list ... rsync: link_stat "/Volumes/No Name/." failed: Invalid argument (22)

done


sent 29 bytes received 20 bytes 98.00 bytes/sec

total size is 0 speedup is 0.00

rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]



Help. How do I make this work?

iMac G5 2GHz, FCE HD 3.5, Mac OS X (10.4.9)

Posted on Jan 20, 2014 4:45 PM

Reply
12 replies

Jan 21, 2014 4:24 AM in response to scott997

I don't think the problem has anything to do with the actual rsync command. It works when I copy it to the terminal and it does not work when it is in a .sh file (or Applescript "do shell script" command). Other parts of the .sh file work, so it is executing.


Is there some sort of problem with the new Gatekeeper and rsync?


Just to be clear, the soure is: '/Volumes/No Name/'. The destination is: '/Users/scott/Documents/Documents/Backup_USB_Drive/Backup_New/'

Jan 21, 2014 8:26 AM in response to scott997

Thanks Pierre. That worked for my by itself, but not in the script. I finally figure out that the problem is caused by checking to see if "No Name" is mounted.


Applescript check if mounted:

tell application "System Events" to get the name of every disk

if result contains findDisk then return true


shell check if mounted:

if [[ -e /Volumes/No\ Name ]]


If I use either method to test if the USB drive is mounted, I get an error (Applescript and shell). If I do not do the test, the script works. I even tried using a delay before the rsync command, but that did not work.


Does anyone have any idea why checking the existance of a drive would cause rsync to fail? Thanks.

Jan 21, 2014 8:49 AM in response to scott997

Without seeing the relevant portion of the script I can only guess, but System Events will only return the name of the disk, not its path. if findDisk is "/volumes/..." that applescript would never find it.


That doesn't seem related to the error you're getting, though, so I think the problem may be a race condition: The system starts advertising that the disk is there before the disk is fully mounted, which causes rsync to hiccup. you might try this:


set isMountedLine to do shell script "diskutil info " & findDIsk & " | grep Mounted:"

if isMountedLine contains "Yes" then return true

Jan 21, 2014 9:01 AM in response to scott997

Maybe I'm missing the point, but this seems to work for me:


try

POSIX file "Volumes/No Name/" as alias -- alias "No Name:"

on error

display dialog "Where is volume “No Name”?"

end try


do shell script "rsync -azv --ignore-existing --delete --exclude='.*' '/Volumes/No Name/' '/Users/scott/Documents/Documents/Backup_USB_Drive/Backup_New/'"

Jan 21, 2014 11:27 AM in response to scott997

Pierre,

That also works for me most of the time. However, occationally I get an error. Running the script a second time usually works. I noticed this same behavior for my script under Snow Leopard. If I do not check that the volume is mounted the script works every time. Thanks for your help.


Thanks twtwtw,

But your method seem to result in the same error I was having.


Thanks Tony,

But I don't need to mount the volume. It should already be mounted. I just wanted to double check that it was indeed mounted.

Mar 28, 2014 11:57 AM in response to scott997

I had the same issue and I think I figured it out:


Before:


SOURCE="/Users/myusername/basedir"

DEST="/Volumes/My\\ Passport/"


rsync -avi "$SOURCE/childdir" "$DEST"


rsync: mkdir "/Volumes/My\ Passport/childdir" failed: No such file or directory (2)

rsync error: error in file IO (code 11) at /SourceCache/rsync/rsync-42/rsync/main.c(544) [receiver=2.6.9]

rsync: connection unexpectedly closed (8 bytes received so far) [sender]

rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [sender=2.6.9]



After:


SOURCE='/Users/myusername/basedir'

DEST='/Volumes/My Passport/'


rsync -avi "$SOURCE/childdir" "$DEST"


This executes successfully.

Problems with rsync scripting

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.