pavelpantyukhin

Sessions Backup — Applescript

Feb 25th, 2015
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tell application "Console"
  2. activate
  3. ---set the BackupLog filename info
  4. set {year:y, month:m, day:d, hours:h, minutes:min, seconds:sec} to (current date)
  5.  
  6.  
  7. end tell
  8. log "Starting Script"
  9. --set the variables
  10. set studio to "STUDIONAME"
  11. set userName to short user name of (system info)
  12. set newFileName to "BackupLog" & "_" & userName & "--" & d & ":" & (m as integer) & ":" & y & "--" & h & "h" & min & ".log"
  13. set rsync_error_flag to false -- set a boolean flag to test for error condition
  14. set backup_error_flag to false -- set a boolean error flag for backup move to false
  15.  
  16. delay 2
  17.  
  18. do shell script "logger *** STARTING BACKUP SCRIPT for " & studio
  19.  
  20. tell application "Finder"
  21. set mounted_Disks to list disks
  22. if mounted_Disks contains "SERVER SHARE" then
  23. eject "SERVER SHARE"
  24. delay 10
  25. do shell script "mount -t afp afp://SERVER SHARE LOCATION"
  26. delay 10
  27.  
  28. else if mounted_Disks does not contain "SERVER SHARE" then
  29. do shell script "logger Mounting SERVER SHARE"
  30. do shell script "mount -t afp afp://SERVER SHARE LOCATION"
  31. delay 10
  32. end if
  33. do shell script "logger SERVER SHARE mounted"
  34. delay 3
  35. do shell script "logger Backup Script Starting"
  36.  
  37. try -- start of the try catch block
  38.  
  39. do shell script "$HOME/mnt/scripts/" & studio & "_BackupV5.sh // &> $HOME/mnt/Logs/" & newFileName -- calls rsync shell script, this is the script that can produce an error
  40. on error error_string number error_number -- if we catch an error set the returned error to error_string & error_number variables
  41. set rsync_error_flag to true -- if we catch error set the flag to true
  42. end try -- end of the try catch block
  43.  
  44. do shell script "logger -f $HOME/mnt/Logs/" & newFileName -- writes the log file
  45.  
  46. end tell
  47. tell application "Finder"
  48. eject "SERVER SHARE"
  49. delay 10
  50. end tell
  51. tell current application
  52. activate
  53. if rsync_error_flag then -- if flag is true then display a dialogue showing errors
  54. display dialog "Backup Script Failed...
  55. " & (error_string) & "
  56. Error code : " & (error_number) & "
  57. Check Backup Logs for More Info" buttons {"Cancel", "OpenLog"} default button 2
  58.  
  59. if the button returned of the result is "Cancel" then
  60. cancel -- action for 1st button goes here  
  61. else
  62. do shell script "open $HOME/mnt/Logs" -- action for 2nd button goes here   
  63. end if
  64. end if
  65.  
  66. if rsync_error_flag is false then -- rsync completed ok so now we move data to Backup folder
  67. try
  68. do shell script "logger - Starting Backup Move Operation ADD HOUSEKEEPING"
  69. on error error_string number error_number
  70. set backup_error_flag to true -- if error moving folder then set flag to true
  71. end try
  72. if backup_error_flag then
  73. display dialog "Backup Move Failed...
  74. " & (error_string) & "
  75. Error code : " & (error_number)
  76.  
  77. else -- if backup error flag is false do this  
  78. display dialog "Backup Script Complete"
  79. end if
  80.  
  81. --else -- if backup error flag is false do this
  82. --  display dialog "Backup Script Complete"
  83. end if
  84.  
  85. end tell
  86. tell application "Console"
  87. quit
  88. end tell
Add Comment
Please, Sign In to add comment