Progress bar & UI for rsync?

Here’s a somewhat rudimentary but mostly functional script I’d like to deploy on users’ desktops to push data to a backup server. I’ll probably automate this using Lingon or some such.

If anyone can think of a way to present the user with a progress bar while the rsync is running, or even a window that scrolls the names of the backed up files as they are uploaded, that would be very cool.

It would also be nice to ask the user’s permission before running the backup with an option to defer until a later time. It has to run during the workday because my users are all using laptops which don’t stay connected overnight.

I would appreciate any input from you scripting deities … thanks!

--set destination path to user's shortname and hard drive name, eg "annelk-backup/Macintosh HD"
tell application "Finder"
	set destName to name of (info for (path to home folder)) & "-backup/" & name of startup disk
end tell

--mount the backup server if not mounted
tell application "System Events"
	if not (exists disk "macbackup") then
		tell application "Finder"
			try
				mount volume "afp://macbackup:secretpassword@backup-server.local/macbackup/"
			on error
				display dialog "Couldn't connect to the backup server."
			end try
		end tell
	end if
	
	--create destination path if it doesn't exist
	set remote to disk "macbackup"
	if not (exists folder destName of remote) then
		do shell script "mkdir /Volumes/macbackup/" & destName
	end if
	
	--rsync entire HD except for user's Music & Movies folders, deleting destination files which don't exist on source
	set theShell to "rsync -rltDv --delete --exclude ~/Music --exclude ~/Movies /* /Volumes/macbackup/" & destName
	
end tell
do shell script theShell

Model: MacBook 13"
Browser: Safari 525.28.3
Operating System: Mac OS X (10.5)

I recommend using AppleScript Studio (part of XCode)

You could try Bruce Phillip’s progress bar script.
http://scriptbuilders.net/files/bpprogressbar1.0.html

I’ve used it in a script and it works great. It can be included in an AS application bundle so it portable.

Also here is an thread about it’s use
http://macscripter.net/viewtopic.php?id=13996

On second thought you may not be able to to show a meaningful progress bar with the BP progress bar due to the shell script rSync. Once the shell starts to run the script won’t have any values to increment so that the progress bar will move. You could use finder to move the files but rSync is more efficient. You might be able to show a basic barber pole and have a phrase like “Files copying to Volume Name”. If you did use Finder you could use the count of the files and file names to display under the progress bar on which would update on each loop of the copy block, but again rSync will probably work much faster. Also if you haven’t seen Apple’s Man page on rSync you can find it at
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/rsync.1.html

Let us know what you work out.

Good luck,
MT

Your best bet may be to use NSTask. Do a --dry-run --stats first to get the information about the transfer and then when you get updates from the task, increment the progress bar.

Also, rsync has an “–progress” option to display the progress but this only works as you would expect in Terminal. If you run the task from AppleScript, all the results are returned once the task is finished. The same thing goes when piping out to a file.

Here are some sites to check out.
http://macosx.com/forums/software-programming-web-scripting/4522-better-way-read-nstask.html
http://borkware.com/quickies/one?topic=NSTask
http://lists.apple.com/archives/Automator-dev/2008/Dec/msg00005.html

Thanks everyone. And another question - how do I update rsync to version 3? There is a tutorial on Bombich’s site to do this, but I hit a wall every time I get to “configure install”.

I just updated my rsync to v3 with no errors. Are you copying and pasting the commands to the terminal? The configure command needs the “./” in front of it.

What is the error you are getting?

When I get to this part:

/prepare-source
./configure
make
sudo make install

I get “command not found”

Is that a “typo” in the post where you have “/prepare-source” or is that how you typed it in Terminal? It should have a period in front of it just like “./configure” does. Also, are you putting all those commands in at one time? If so, do each one by itself and wait until that process has finished before issuing the next command.

no, I typed it right - just pasted it wrong when I wrote my last post.

I’m sure this is some very elementary Unix thing that I’m completely overlooking.

Here’s what Terminal has to say:

[my-macbook:~/Desktop/rsync-3.0.6] me% ./prepare-source

./prepare-source: line 26: make: command not found

I take it from your original comment that you have started this process from scratch several times? If not, I would delete the rsync folder and try again.

Other than that, I do not understand why is it not working. I have updated three computers, from Tiger to Snow Leopard, with no issues.

You might do a video. It always helps to see someone working to catch the error.

DUH. I didn’t have Xcode installed.

I installed Xcode and it worked.

Told you it was something dumb …!

Not dumb at all. I always assume, and I shouldn’t, that everyone has Xcode installed.

Glad you got it worked out.

Thanks for the help!