Monday, December 11, 2017
  • Index
  •  » Code Exchange
  •  » Rsync Wrapper a scriptable Cocoa application for the rsync utility

#1 2014-06-23 01:47:48 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Rsync Wrapper a scriptable Cocoa application for the rsync utility

Rsync Wrapper is a simple Objective-C wrapper for the rsync utility which provides AppleScript support and the ability to display a progress bar and transfer statistics.

rsync is an open source utility that provides fast incremental file transfer.

The rsync version that comes with Mac OS X is quite old (2.6.9).
Rsync Wrapper uses the most recent stable version (3.1.0) including the following Mac OS X related patches:

compression.diff
crtimes.diff
fileflags.diff

The AppleScript dictionary contains one command, the source and destination references can be POSIX paths, HFS paths or alias specifiers

rsync_wrapper2.png




The rsync command returns a record


rsync_wrapper1.png


This is a code example, the arguments must be passed as a list of strings, an explicit quotation is not necessary

Applescript:


tell application "Rsync Wrapper"
   activate
   set {exit code:exitCode, error message:errorMessage, items transferred:filesCopied, statistics:stats} to rsync from source "/path/to/source" to destination "/path/to/destination" arguments {"-au", "--exclude=.DS_Store"}
   
end tell
if exitCode is not 0 then
   display dialog errorMessage
else
   display dialog stats
end if

Notes:

• To avoid interferences while running rsync the following flags are ignored:  -v, --verbose, --progress, --stats, --dry-run.
• Any trailing slashes in the source and destination paths are ignored too.
• The rsync AppleScript command works synchronously, the next code line is executed after completion.
• I haven't tested a real large file transfer, maybe a timeout block is needed

• Rsync Wrapper quits automatically after task completion.


The application is code-signed, minimum system requirements: 10.7 Lion


Download: Rsync Wrapper.zip


The software is distributed “as is”, without any warranty nor responsibility for potentially lost data


regards

Stefan

Offline

 

#2 2014-07-30 08:56:36 pm

scottfwalter
Member
Registered: 2014-07-30
Posts: 20

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Any chance you can post the source code to your wrapper?  I'd like to take a look at it and see how you wrote it in case in the future I'd like to write a wrapper for some other command.

Offline

 

#3 2014-08-09 11:51:48 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

The code calls rsync via NSTask very similar to the code in this thread, but written in Objective-C
MacScripter / Multi-task rsync command within ASOC app.

To perform rsync synchronously in the AppleScript environment the NSScriptCommand subclass is suspended and resumed after completion


regards

Stefan

Offline

 

#4 2014-09-19 05:53:45 am

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 538
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Stefan,
im on 10.7.5 and rsync crashes all the time if i click your rsync package…

[code]Crashed Thread:  Unknown

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007fff5fc01028

Backtrace not available[/code]
However, i see a rsync Wrapper in 'Activity Monitor'. Do i need some patches or additional bins ?

Offline

 

#5 2014-09-19 09:11:49 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

sorry, I can't test it on Lion, but actually it's supposed to be compatible with 10.7


regards

Stefan

Offline

 

#6 2015-07-16 07:28:29 pm

jarvphot
Member
Registered: 2015-07-16
Posts: 5

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Hi. I just found this post and downloaded this very useful app; thank you for sharing.

I have encountered a problem that I'm hoping will be an easy fix. When I go to use the Rsync Wrapper with this applescript:

Applescript:

tell application "FileMaker Pro Advanced"
   set sourceFolder to cell "Paths::Path to job folder" of current record & "/RAW"
   set targetFolder to cell "Paths::Path to archive folder" of current record
end tell

tell application "Rsync Wrapper"
   activate
   set {exit code:exitCode, error message:errorMessage, items transferred:filesCopied, statistics:stats} to rsync from source sourceFolder to destination targetFolder arguments {"-a"}
   
end tell

This works as expected; a folder named RAW is created at the target and the files are copied to it.

However when I use the code below with the trailing "/" in the path, my understanding is that only the files should be copied, with no RAW folder created in the target.

Instead, the behavior is the same; a a folder named RAW is created at the target and the files are copied to it.:

Applescript:


tell application "FileMaker Pro Advanced"
   set sourceFolder to cell "Paths::Path to job folder" of current record & "/RAW/"
   set targetFolder to cell "Paths::Path to archive folder" of current record
end tell

tell application "Rsync Wrapper"
   activate
   set {exit code:exitCode, error message:errorMessage, items transferred:filesCopied, statistics:stats} to rsync from source sourceFolder to destination targetFolder arguments {"-a"}
   
end tell

I would appreciate any help in getting this to work so that no RAW folder is created in the target. Thanks!!


Eric

Last edited by jarvphot (2015-07-16 07:29:59 pm)


Filed under: rsync wrapper

Offline

 

#7 2015-07-17 03:32:20 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

The reason for this behavior is, that the path method of NSURL – it strips the path portion of a valid URL – returns always a file path without trailing slash

I changed the code to preserve the trailing slash, same link.


regards

Stefan

Offline

 

#8 2015-07-17 10:40:10 am

jarvphot
Member
Registered: 2015-07-16
Posts: 5

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Thank you. That fixes my issue.

The change created a small bug perhaps...in the new version you just posted, the progress meter no longer displays the filename being copied.

Your help is very appreciated.

Eric

Offline

 

#9 2015-07-17 11:29:32 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

That was very tricky to figure out the proper algorithm to filter the line which includes the filename.
In the non-trailing slash version the line starts always with the enclosing folder name.

But eventually I got it.

Same link.


regards

Stefan

Offline

 

#10 2015-07-17 04:37:42 pm

jarvphot
Member
Registered: 2015-07-16
Posts: 5

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Working perfectly for me now. Thank you.

If you are adding any more features to Rsync Wrapper, one that I would suggest would be to display the size of the file that is currently being transferred after it's name. This could serve as an additional reminder to the user to be patient when a large file is transferring.

Thanks again,

Eric

Offline

 

#11 2015-07-19 03:01:35 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Thanks for the suggestion. It's implemented. Same link


regards

Stefan

Offline

 

#12 2015-07-20 02:19:52 pm

jarvphot
Member
Registered: 2015-07-16
Posts: 5

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Thank you for creating this useful tool.

Eric

Offline

 

#13 2015-11-16 01:50:31 pm

jarvphot
Member
Registered: 2015-07-16
Posts: 5

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Hi Stefan,

I have been using rsync wrapper for several months now and I find it extremely helpful.

I don't know if this a tool that you are interested in developing further, but I have encountered two issues that if resolved would make this even more awesome smile

~ If the user needs to abort a transfer for any reason there is no easy way to do that.

~ If the user starts a second simultaneous transfer using rsync wrapper, it is unclear what happens. The first dialog is replaced by the second dialog...but the user can't tell if the first transfer was interrupted or if it is ongoing in the background. It would be ideal if a second window were to open instead.

Even if there's no time to work on any of that, this is still a very useful tool.

thanks!

Eric

Offline

 

#14 2017-07-03 09:51:49 am

PhilippePierre
Member
From:: Tokyo, JPN.
Registered: 2017-07-03
Posts: 4

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Hello Stefan,
few years later Rsync Wrapper is still a gem. Being able to add progress bar to rsync related Applescript is a real gift, thank you very much for it!
Though i am struggling to make it work when doing backups to NAS : timeout gets on the way.
Progress bar just shows forever "preparing...", script gets stuck (beach ball), no synchronized backup gets done.
Sorry i am just in first year Applescript Kindergarten and do not really know how to fix this problem when a server connection is involved (server volume is, of course, mounted; it works perfectly between hard disks, internal or external).
Thank you very much in advance for your help*.
Philippe.
P.-S.
Systems in use : the latest versions of El Capitan & Sierra
(*) Please let me know if donation required.

Model: iMac 2011
AppleScript: 2.5
Browser: Safari 603.2.5
Operating System: Mac OS X (10.10)

Offline

 

#15 2017-07-04 02:55:06 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

I don't have a network volume so I can't test anything.

The workflow of Rsync Wrapper performs first a dry run to get the statistics before doing the actual copy job

What happens when you run rsync in Terminal.app with the following syntax

rsync --stats --dry-run /path/to/source /path/to/destination

regards

Stefan

Offline

 

#16 2017-07-04 06:38:01 pm

PhilippePierre
Member
From:: Tokyo, JPN.
Registered: 2017-07-03
Posts: 4

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Thanks a lot Stefan for your quick feedback.

What happens when you run rsync in Terminal.app with the following syntax :
rsync --stats --dry-run /path/to/source /path/to/destination


Result ↓
---------------------------------------------------------------------------------
skipping directory /Users/(MyAccount)/Desktop/source

Number of files: 0
Number of files transferred: 0
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 5
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 21
Total bytes received: 20

sent 21 bytes  received 20 bytes  82.00 bytes/sec
total size is 0  speedup is 0.00
---------------------------------------------------------------------------------

I previously forgot to specify that Rsync Wrapper works fine on the network volume if source folder weights only few GB.
Trouble starts with more than, let say, roughly 10~20 GB or so...

Please let me know if more tests or information needed.
Thank you in advance for your help, deeply appreciated.

Offline

 

#17 2017-07-10 10:05:19 am

PhilippePierre
Member
From:: Tokyo, JPN.
Registered: 2017-07-03
Posts: 4

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Stefan,
any hope for a soon improvement of this very fine rsync wrapper except when used with a network volume or USB external hard disk (same problem)?
If not, I'll try to modify my apple script for a one by one folder backup sync to involve less data at once.
Thanks in advance for clarifying this.
Best regards,
Philippe.
(again, if donation (quickly) required, please let me know. Or should I know... ;-)).

Offline

 

#18 2017-07-10 10:08:35 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Unfortunately there is no hope at the moment. sorry.


regards

Stefan

Offline

 

#19 2017-07-10 10:12:40 am

PhilippePierre
Member
From:: Tokyo, JPN.
Registered: 2017-07-03
Posts: 4

Re: Rsync Wrapper a scriptable Cocoa application for the rsync utility

Thanks for your quick reply, understood.
Enjoy your summer!

Offline

 
  • Index
  •  » Code Exchange
  •  » Rsync Wrapper a scriptable Cocoa application for the rsync utility

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)