Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lee UK

macrumors newbie
Original poster
Sep 17, 2010
2
0
Hi. Long story short -
Trying to create backup image of bootcamp partition onto external HDD. Using winclone perl script and automatically creating and replacing relevant backup folders depending on times of previous backups. I have set up root user. I have edited sudo visudo so I am not prompted for password while running perl script and everything works…. almost.
The ‘run the script’ section within the applescript takes 20-30 minutes to run. Later on the Finder move action takes about 10-15 minutes to run which is why I have inserted the timeout statement to avoid Finder timing out while waiting for the move to finish.
The disk ‘Otherstuff’ exists. The folder within it called Backups exists and the 3 folders within that folder called WindowsMonthlyBackups, WindowsWeeklyBackups and WindowsDailyBackups all exist. Macintosh HD:Users:leeandnessahome:Documents:windowsbackup exists.
The delete and recreate works fine. Check that Bootcamp and Otherstuff exist works fine. The perl script works fine. The Windows.sparsebundle plus 3 other files are successfully created in the folder Macintosh HD:Users:leeandnessahome:Documents:windowsbackup:backup but then it falls apart. In the example Event Log below you can see that the applescript started checking for the date of the ‘size’ file if it exists and just decided to stop for no reason. I left t for an hour after it stopped but it was just hung. 4 hours later I ran it and it worked fine. On this occasion there was no need to copy files because Daily, Weekly and Monthly backups were up to date. Sometimes it runs through this section successfully and instead stops in the middle of renaming the folders section later on.
If I cut out the delete and recreate section (except the property line) and cut out the perl section, and ensure that the relevant files are already located in Macintosh HD:Users:leeandnessahome:Documents:windowsbackup:backup and ensure that a backup is required everything works fine including the copying!
I’m so close and so frustrated. What is wrong please?

Here is the Applescript (sorry don't know how to present it nicely)

Code:
--
--DELETE AND RECREATE BACKUP FOLDER
--
property backup_folder : "Macintosh HD:Users:leeandnessahome:Documents:windowsbackup:backup"
ignoring application responses
    tell application "Finder"
        delete folder backup_folder
        make new folder at folder "windowsbackup" of folder "Documents" of home with properties {name:"backup"}
    end tell
end ignoring
 --[LIST]
[*][LIST]
[*]CHECK THAT BOOTCAMP AND Otherstuff BOTH EXIST[/LIST] [/LIST]--
tell application "Finder"
    if (exists disk "BOOTCAMP") and (exists disk "Otherstuff") then
        set the run_message to true
    else
        set the run_message to false
    end if
end tell
 --[LIST]
[*][LIST]
[*]RUN THE SCRIPT[/LIST] [/LIST]--
if run_message is true then
    set return_message to do shell script "sudo perl  /Applications/Winclone.app/Contents/Resources/winclone.perl  -image_dir=/Users/leeandnessahome/Documents/windowsbackup/backup  -ntfstools_dir=/Library/NTFSProgs -create -q -remove_pagefile  -image_format=diskimage -diskimagetype=sparse"
end if
 --[LIST]
[*][LIST]
[*]FIND TYPE OF BACKUP[/LIST] [/LIST]--
set backup_type to "none"
if run_message is true then
    tell application "Finder"
        if backup_type is "none" then
            set test_type to "Monthly"
            set test_time to 30
            if exists file "size" of folder (test_type & "1") of folder  ("Windows" & test_type & "Backups") of disk "Otherstuff" then
                set the Date_mod to modification date of file "size" of folder  (test_type & "1") of folder ("Windows" & test_type &  "Backups") of disk "Otherstuff"
                if Date_mod > ((current date) - test_time) then set backup_type to test_type
            else
                set backup_type to test_type
            end if
        end if
        
        if backup_type is "none" then
            set test_type to "Weekly"
            set test_time to 7
            if exists file "size" of folder (test_type & "1") of folder  ("Windows" & test_type & "Backups") of disk "Otherstuff" then
                set the Date_mod to modification date of file "size" of folder  (test_type & "1") of folder ("Windows" & test_type &  "Backups") of disk "Otherstuff"
                if Date_mod > ((current date) - test_time) then set backup_type to test_type
            else
                set backup_type to test_type
            end if
        end if
        
        if backup_type is "none" then
            set test_type to "Daily"
            set test_time to 1
            if exists file "size" of folder (test_type & "1") of folder  ("Windows" & test_type & "Backups") of disk "Otherstuff" then
                set the Date_mod to modification date of file "size" of folder  (test_type & "1") of folder ("Windows" & test_type &  "Backups") of disk "Otherstuff"
                if Date_mod > ((current date) - test_time) then set backup_type to test_type
            else
                set backup_type to test_type
            end if
        end if
    end tell
end if
 --[LIST]
[*][LIST]
[*]MOVE BACKUP FOLDERS AND CREATE NEW BACKUP FOLDER[/LIST] [/LIST]--
if backup_type is "none" then
    beep
else
    tell application "Finder"
        with timeout of (50 * 60) seconds
            
            if exists folder (backup_type & "5") of folder ("Windows" &  backup_type & "Backups") of disk "Otherstuff" then delete folder  (backup_type & "5") of folder ("Windows" & backup_type &  "Backups") of disk "Otherstuff"
            delay 10
            if exists folder (backup_type & "4") of folder ("Windows" &  backup_type & "Backups") of disk "Otherstuff" then set name of  folder (backup_type & "4") of folder ("Windows" & backup_type  & "Backups") of disk "Otherstuff" to (backup_type & "5")
            delay 10
            if exists folder (backup_type & "3") of folder ("Windows" &  backup_type & "Backups") of disk "Otherstuff" then set name of  folder (backup_type & "3") of folder ("Windows" & backup_type  & "Backups") of disk "Otherstuff" to (backup_type & "4")
            delay 10
            if exists folder (backup_type & "2") of folder ("Windows" &  backup_type & "Backups") of disk "Otherstuff" then set name of  folder (backup_type & "2") of folder ("Windows" & backup_type  & "Backups") of disk "Otherstuff" to (backup_type & "3")
            delay 10
            if exists folder (backup_type & "1") of folder ("Windows" &  backup_type & "Backups") of disk "Otherstuff" then set name of  folder (backup_type & "1") of folder ("Windows" & backup_type  & "Backups") of disk "Otherstuff" to (backup_type & "2")
            delay 10
            make new folder at folder ("Windows" & backup_type &  "Backups") of disk "Otherstuff" with properties {name:backup_type &  "1"}
            delay 10
            copy every item in folder backup_folder to folder (backup_type &  "1") of folder ("Windows" & backup_type & "Backups") of disk  "Otherstuff"
        end timeout
    end tell
end if
Here is Event Log 1 - it just stopped after establishing that file called 'size' exists. It was then supposed to get the modification date but instead just hung!

Code:
tell application "Finder"
    delete folder "Macintosh HD:Users:leeandnessahome:Documents:windowsbackup:backup"
        current application
    make new folder at folder "windowsbackup" of folder "Documents" of home with properties {name:"backup"}
        current application
    exists disk "BOOTCAMP"
        true
    exists disk "Otherstuff"
        true
end tell
tell current application
    do shell script "sudo perl  /Applications/Winclone.app/Contents/Resources/winclone.perl  -image_dir=/Users/leeandnessahome/Documents/windowsbackup/backup  -ntfstools_dir=/Library/NTFSProgs -create -q -remove_pagefile  -image_format=diskimage -diskimagetype=sparse"
        "current size is 129321926656
partition id is 0x07
partition format is NTFS
diskimagetype is sparse
image path is /Users/leeandnessahome/Documents/windowsbackup/backup/WindowsImage device is /dev/disk2
cleaning up: Mounting Disk
Volume BOOTCAMP on /dev/disk0s3 mounted"
end tell
tell application "Finder"
    exists file "size" of folder "Monthly1" of folder "WindowsMonthlyBackups" of disk "Otherstuff"
        true
    get modification date of file "size" of folder "Monthly1" of folder "WindowsMonthlyBackups" of disk "Otherstuff"
        date "Wednesday, September 15, 2010 18:52:00"
    current date
        date "Friday, September 17, 2010 17:53:50"
    exists file "size" of folder "Weekly1" of folder "WindowsWeeklyBackups" of disk "Otherstuff"
        true
Here is Event Log 2 - 4 hours later, no problems

Code:
tell application "Finder"
    delete folder "Macintosh HD:Users:leeandnessahome:Documents:windowsbackup:backup"
        current application
    make new folder at folder "windowsbackup" of folder "Documents" of home with properties {name:"backup"}
        current application
    exists disk "BOOTCAMP"
        true
    exists disk "Otherstuff"
        true
end tell
tell current application
    do shell script "sudo perl  /Applications/Winclone.app/Contents/Resources/winclone.perl  -image_dir=/Users/leeandnessahome/Documents/windowsbackup/backup  -ntfstools_dir=/Library/NTFSProgs -create -q -remove_pagefile  -image_format=diskimage -diskimagetype=sparse"
        "current size is 129321926656
partition id is 0x07
partition format is NTFS
diskimagetype is sparse
image path is /Users/leeandnessahome/Documents/windowsbackup/backup/WindowsImage device is /dev/disk2
cleaning up: Mounting Disk
Volume BOOTCAMP on /dev/disk0s3 mounted"
end tell
tell application "Finder"
    exists file "size" of folder "Monthly1" of folder "WindowsMonthlyBackups" of disk "Otherstuff"
        true
    get modification date of file "size" of folder "Monthly1" of folder "WindowsMonthlyBackups" of disk "Otherstuff"
        date "Wednesday, September 15, 2010 18:52:00"
    current date
        date "Friday, September 17, 2010 21:38:44"
    exists file "size" of folder "Weekly1" of folder "WindowsWeeklyBackups" of disk "Otherstuff"
        true
    get modification date of file "size" of folder "Weekly1" of folder "WindowsWeeklyBackups" of disk "Otherstuff"
        date "Thursday, September 16, 2010 17:52:08"
    current date
        date "Friday, September 17, 2010 21:38:44"
    exists file "size" of folder "Daily1" of folder "WindowsDailyBackups" of disk "Otherstuff"
        true
    get modification date of file "size" of folder "Daily1" of folder "WindowsDailyBackups" of disk "Otherstuff"
        date "Thursday, September 16, 2010 22:26:45"
    current date
        date "Friday, September 17, 2010 21:38:45"
end tell
tell current application
    beep
end tell
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
No idea why it is hanging (maybe the file is busy or something?). But, it looks like you're trying to calculate months and weeks and days off dates. AFAIK AppleScript's date math is based on seconds so subtracting the generic number "30" from a date would give you a new date 30 seconds in the past, which is probably not what you want. So I think it should be more like

Code:
set test_time to (30 * days)
 

Lee UK

macrumors newbie
Original poster
Sep 17, 2010
2
0
Hi Hirez. You are absolutely right. Thanks for that. I've also noticed I was using > but should be using <. I am trialling using delay 1 or delay 5 during the find backup type section and it seems to have fixed the problem of hanging (I think). I have also moved the type of backup section in front of the perl script section to save running the perl script so often.

Now I would like to specify the folders and disks in a 'setup' section right at the beginning of the script to make it more easily useful to other people. Can I specify 'home' somehow in the property line right at the beginning of the script rather than using the name of my home folder? So something like
Code:
property backup_folder :"home:Documents:windowsbackup:backup"
instead of
Code:
property backup_folder : "Macintosh HD:Users:leeandnessahome:Documents:windowsbackup:backup"
I tried using set instead, but that won't work if the folder does not exist. Thanks.
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
Yeah, AppleScript can be a bit flakey and temperamental so adding things like small delays as you are can work in some cases. You can get the home folder with

Code:
(path to home folder)
 

ThoFre97

macrumors newbie
Nov 20, 2010
1
0
How's it Going?

Hello Lee UK,

I have been looking for a script like this. I don't know anything about writing AppleScripts so it is beyond doing it myself. I'm hoping you have been able to complete it?

Thanks,
Tom
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.