Progress of Backup Script

Hi Guys

I have a backup script that copies my main home folders to an external drive. At present the script runs, but i have no idea what % it has done, or what area it is currently copying.

Script:

    do shell script "cp -R $HOME/Data1 /Volumes/CAPSULE/"

do shell script "cp -R $HOME/Data2 /Volumes/CAPSULE/"

do shell script "cp -R $HOME/Data3 /Volumes/CAPSULE/"

Is there anyway to have a dialog box that stays up and stated what are the code is copying e.g:

   Dialog display "Started"
    
   do shell script "cp -R $HOME/Data1 /Volumes/CAPSULE/"
   
  Dialog Display "Copying Pictures" 

   do shell script "cp -R $HOME/Data2 /Volumes/CAPSULE/" 

or is there a way to get the system to produce a dialog with a process bar that shows the % of what has been complete?

Cheers for any help

You best do this with AppleScript Studio? Feel like starting? http://macscripter.net/viewtopic.php?id=25631

If you want to do it with applescript and display dialog-commands? Take a look at this:

set folderToCopy to (choose folder with prompt "Please choose a folder to copy:") as string
set copyDirectory to (choose folder with prompt "Please choose backup directory:") as string
set copyDirectory to (POSIX path of copyDirectory)
set copyDirectory to ConvertName(copyDirectory)

tell application "Finder" to set allFilesToCopy to every item of alias folderToCopy
repeat with i from 1 to (count allFilesToCopy)
	set theFileToCopy to (item i of allFilesToCopy) as alias
	set thePOSIXPath to (POSIX path of theFileToCopy) as string
	display dialog ("I will now copy file " & (i as string) & "/" & ((count allFilesToCopy) as string) & ":" & return & return & thePOSIXPath) as string
	set terminalPath to ConvertName(thePOSIXPath)
	do shell script ("cp -R " & terminalPath & " " & copyDirectory) as string
end repeat

display dialog "All went right! Goodbye!" buttons "OK" default button 1

(* ===== HANDLERS ===== *)
on ConvertName(PosixPathString)
	set NewName to {}
	repeat with i in PosixPathString
		if (i as string) is " " then set end of NewName to "\\ "
		if (i as string) is not " " then set end of NewName to (i as string)
	end repeat
	
	set NewName to NewName as string
	return NewName
end ConvertName

Hey IEF2

Cheers for the link, ive got XCode installed.

I am looking at this thread http://macscripter.net/viewtopic.php?id=24760

in there is the kind of result i am after, with a display box, stating process & amount of files to copy etc

I am gonna have a play around, the xcode layout isn’t as under friendly as i wish it was but you have to start somewhere.

Rather than the user pick the folder to copy i want to build in the presets of my apple script e.g

do shell script “cp -R $HOME/Data1 /Volumes/CAPSULE/”

And as it works it will display infomation

Well you if you want to be able to change the paths you could use the user defaults.
Tutorial: http://macscripter.net/viewtopic.php?id=24666
(look at the Gentlemen Prefer Preferences part)

Then you could change the preferences by adding a new menu item to your app’s menu bar, connect it to an applescript and it should be something like this:

on clicked menu item theObject()
	if name of theObect is NAMEOFMENUITEM then
		set newFolderToCopy to (choose folder with prompt "Please choose the folder to copy:") as alias
		set newCopyDestination to (choose folder with prompt "Please choose the backup folder:") as alias
		set newFolderToCopy to ConvertName((POSIX path of newFolderToCopy) as string)
		set newCopyDestination to ConvertName((POSIX path of newCopyDestination) as string)
		-- DON'T FORGET TO ADD THE RIGHT HANDLERS TO THE END OF THE SCRIPT (see earlier posts)
	
		tell user defaults to set contents of default entry "FOLDERTOCOPY" to newFolderToCopy
		tell user defaults to set contents of default entry "COPYDESTINATION" to newCopyDestination
	end if
end clicked

You could always split it in two menu items.

If you are not willing to change the paths later, you could use a static string in your application.

hey guys, am gonna go for a different approach:

is there any way i can get the code to launch in terminal and it display what it is doing e.g verbose

do shell script "cp -R $HOME/Data1 /Volumes/CAPSULE/"

do shell script "cp -R $HOME/Data2 /Volumes/CAPSULE/"

do shell script "cp -R $HOME/Data3 /Volumes/CAPSULE/"

This way i can see what files are being coppied and will be able to see progress

Also, has anyone got any ideas how when you launch terminal via applescript, to get it to launch as Homebrew rather than the standard white & black?

Cheers

Update: Fixed the colour issue :


tell application "Terminal"
	activate
	
	set the background color of window 1 to "black"
	set the normal text color of window 1 to "green"
	set the number of columns of window 1 to 50
	set the number of rows of window 1 to 15
	set the position of window 1 to {0, 20}
	
end tell

  • Note you must use lower case in colour name, if you use Caps it Fails

Found the answer to the verbose part, cant find it for the terminal skin though :frowning:

cp

Copy files.

Syntax
cp [-R [-H | -L | -P]] [-fi | -n] [-pvX] Source_file Target_file

  cp [-R [-H | -L | -P]] [-fi | -n] [-pvX] Source_file(s) Target_Folder

Key:
-R Copy the folder and subtree (recursive).
If source_file designates a directory, cp copies the directory and
the entire subtree connected at that point. If the source_file
ends in a /, the contents of the directory are copied rather than
the directory itself. This option also causes symbolic links to be
copied, rather than indirected through, and for cp to create special
files rather than copying them as normal files. Created
directories have the same mode as the corresponding source directory,
unmodified by the process’ umask.

-H Symbolic links on the command line are followed.
(but Symbolic links encountered in the tree traversal are not followed.)

-L All symbolic links are followed.

-P No symbolic links are followed. This is the default.

-f For each existing destination pathname, remove it and create a new
file, without prompting for confirmation regardless of its permissions.
(The -f option overrides any previous -i or -n options.)

-i Cause cp to write a prompt to the standard error output before
copying a file that would overwrite an existing file. If the
response from the standard input begins with the character y' or Y’, the file copy is attempted. (The -i option overrides any
previous -f or -n options.)

-n Do not overwrite an existing file. (The -n option overrides any
previous -f or -i options.)

-p Cause cp to preserve the following attributes of each source file
in the copy: modification time, access time, file flags, file mode,
user ID, and group ID, as allowed by permissions. Access Control
Lists (ACLs) will also be preserved.

    If the user ID and group ID cannot be preserved, no error message
    is displayed and the exit value is not altered.

-v Verbose - show files as they are copied.

-X Do not copy Extended Attributes (EAs) or resource forks.

Im using this script at the moment:

 

tell application "Terminal"
	
	do script "cp -Rv $HOME/Downloads /Volumes/CAPSULE/"
	do script "cp -Rv $HOME/Pictures /Volumes/CAPSULE/"
	do script "cp -Rv $HOME/Music /Volumes/CAPSULE/"
	do script "cp -Rv $HOME/Documents /Volumes/CAPSULE/"
	do script "cp -Rv $HOME/Movies /Volumes/CAPSULE/"

	
end tell

Issue is that it opens various terminal commands, is there any way to get it to do 1 part e.g downloads, then move onto pictures etc

Edited:

Iv’e now tried this:

putting the above in a script called a.scpt

then tried this:



tell application "Terminal"
	activate
	
	do script "$Home/Dekstop/a.scpt" in window 1
	
end tell


But i get returned from terminal file or directory doesn’t exist

If i use:

do script “/Users/Jbird/Desktop/a.scpt” in window 1

I get permission denied …

if i try with sudo i get this:

J-Birds-MacBook-Pro:~ Jbird$ sudo /Users/Jbird/Desktop/a.scpt
sudo: /Users/Jbird/Desktop/a.rtf: command not found

Any Ideas Guys??

Shell commands on one line are separated with a semi-colon.

do script "cp -Rv $HOME/Downloads /Volumes/CAPSULE/; cp -Rv $HOME/Pictures /Volumes/CAPSULE/; cp -Rv $HOME/Music /Volumes/CAPSULE/; cp -Rv $HOME/Documents /Volumes/CAPSULE/; cp -Rv $HOME/Movies /Volumes/CAPSULE/"

Why not redirect the output to a log file:


set myLog1 to "/Users/you/Desktop/Archive_Log.log"
set myLog2 to (path to desktop as text) & "Archive_Log.log"

set theDate to (current date) as text
tell application "Console" to activate
tell application "Console" to open myLog2

do shell script "echo " & return & "Start Archiving sequence at " & theDate & ">>" & myLog1
do shell script "cp -Rv $HOME/Data3 /Volumes/CAPSULE/" & ">>" & myLog1

–Peter–

Cheers Both

@ Craig - Calling an Apple Script to run that script via terminal - I have had issues with Permission Denied

Any ideas what i may be missing?

Ive Tried SUDO

Ive Tried With Administrator Privaliages

Ive Tried Looking through all Switchs that can follow CP

Also

Will this action 1 after the other, or will this open 5 terminal windows?

Activating an applescript in Terminal:
osascript “path/to/you/a.scpt”

Why do you want to activate an Applescript from the Terminal?
You can use BP Progressbar (on this forum) or just use my previous post as start.

–Peter–

When i run this this is what i get back as a result:

cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B1.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B2.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B4.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B6.JPG: No such file or directory
cp: /Volumes/CAPSULE/Pictures/Mixture Of Pics/B7.JPG: No such file or directory

That is because you have spaces in the path. Quoting each path will resolve the issue.

Hi Craig - I removed space between pictures and volumes - get the following returned

J-Birds-MacBook-Pro:~ Jbird$ cp -R $HOME/Pictures/Volumes/CAPSULE
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file … target_directory

Sorry, I was looking at the wrong thing. You must have a space between the source and destination folder.

Its Cool Craig, This is sending my head round in loops,

I can understand why its not working - It surely cant be this hard to get terminal to execute what i am trying…

That is an odd error. It is showing a destination path and saying that it does not exist, but that is usually the point since it is making a copy. I suspect it is something to do with “CAPSULE”, but you should be able to reduce the problem until you have identified it.

Do you get other output (e.g. lines that indicate other files are being copied correctly)? Are any of the other directories (Downloads, Music, Documents, Movies) reporting errors like this? Are any of the other directories being copied at all?

What is the CAPSULE volume? (internal, external, local, remote, LAN, WAN)
How it it being accessed? (SATA, USB, FireWire, eSATA; AFP, SMB, NFS, iSCSI)
Is it, as its name suggests, a network-mounted Time Capsule?

First step, simply the command to just the failing part. If it now succeeds, then the problem may have been triggered by one of the preceding events. If it still fails, then continue simplifying.

tell app "Terminal"
do script "cp -Rv $HOME/Pictures /Volumes/CAPSULE/"
end

If this works, then it would seem to indicate that something about the earlier copies is causing the problem. Maybe the destination is unable to keep up with the many requests that cp is generating (bad disk/device?).

Next, try copying into a fresh directory on CAPSULE.

tell app "Terminal"
do script "mkdir /Volumes/CAPSULE/copy-test && cp -Rv $HOME/Pictures /Volumes/CAPSULE/copy-test"
end

Note, the directory will only be “fresh” the first time you run this. You will have to delete the copy-test directory to repeat the test with a truly fresh directory.
If this works, then it could be something inside /Volumes/CAPSULE/Pictures that is broken (a filesystem corruption?). If it is a local disk, I would ask DIsk Utility to Verify and/or Repair the disk to see if it finds any problems.

Next, try eliminating the volume by copying to a destination on the boot volume.

tell app "Terminal"
do script "mkdir /tmp/copy-test && cp -Rv $HOME/Pictures /tmp/copy-test"
end

Note: Same deal with “freshness” here as above.
If this works (and all the rest still failed), then it strongly indicates that the problem is specific to the /Volumes/CAPSULE disk.

If it is still failing in the same way, then it could be a bug in how cp does its work, or it could be a problem with the source files or directories (though, in that case, the misleading error message from cp could still be called a minor bug). Are the files in the Pictures directory accessible and usable? (Can you open them in Preview?)

its funny you say this, i just ran my old script that does

do shell script “cp -R $HOME/Downloads /Volumes/CAPSULE/”

I get permission is denied / cannot find target

error “cp: /Volumes/CAPSULE/Downloads: Permission denied
cp: /Users/JBird/Downloads: unable to copy extended attributes to /Volumes/CAPSULE/Downloads: Permission denied
cp: /Volumes/CAPSULE/Downloads/.DS_Store: No such file or directory” number 1

This is EXTREMELY strange as all that used to happen when the external HDD “Capsule” wasn’t attached all it did was error and say Edit Script

Have i screwed up my permissions on my folders some how? is there a way to reset folders and items to defaults?

Cheers

My cp does not contain any strings like “cannot find target”, but then I am still running 10.4.

I have never seen error messages quite like those, but they still lead me to think that something is wrong (misconfigured, corrupt, otherwise broken) on the CAPSULE device (either at the filesystem level, or maybe the hardware itself).

Did copying to a directory on your boot drive work? If so, it strongly indicates that, in my opinion, the problem is with CAPSULE, not with the script or cp.