Thread: Backup Script..
View Single Post
  #1  
Old 07-16-2003, 11:53 AM
Rekd's Avatar
Rekd Rekd is offline
Community Moderator
 
Join Date: Apr 2003
Location: teh Debug Window
Posts: 1,877
Rekd is on a distinguished road
Backup Script..

Here's a handy script a few of us at eMastercam created to do
backups of current files to a different folder, using a date/time
stamp.

It uses Winzip's Command Line Interface to add the backup file to
a .zip file then delete the backup file.

You can substitute winzip with your archiving program if it accepts
command line arguments. Just make the needed changes to
the "Public Const" section towards the top of the script to assign
your Backup folder and your compression program.

I posted it here instead of the Tech Articles area to preserve
formatting.

Code:
'////////////////////////////////////////////////////////////////////////////////
'//
'//        Author:   Matt Finley mfinley<at>rolingem<dot>com
'//                  Original script by Mick George.
'//          Date:   16/07/2003 08:07 AM
'//     File Name:   _Archiver.vbs
'//
'//   Description:   Makes a backup of the current MC file to the folder specified.
'//                  Use Winzip with command line interface to compress then delete backup file.
'//                  You can get the command line interface here: http://www.winzip.com/wzcline.cgi
'//
'//      Comments:   This script uses wzzip.exe, (WinZip's command line interface) to compress
'//                  the backed up files. Ensure the correct path and arguments for the compression
'//                  you wish to use are entered below. You need to use the truncated name for
'//                  long path names that contain spaces when calling wzzip.exe.
'//                  This script uses -m and -ex to delete the original backup file and
'//                  to use maximum compression.
'// 
'//
'////////////////////////////////////////////////////////////////////////////////


'///////////////// My Constants /////////////////     
Public Const fsoDRIVE_UNKNOWN = 0
Public Const fsoDRIVE_REMOVABLE = 1
Public Const fsoDRIVE_FIXED = 2
Public Const fsoDRIVE_NETWORK = 3
Public Const fsoDRIVE_CDROM = 4
Public Const fsoDRIVE_RAM_DISK = 5 
Public Const DEF_CENTERED = "         "   
Public Const DEF_ERRLOG = "C:\Your Folder\Backups\McScriptErr.log"  ' Path and file for error log
Public Const strZipPath = "C:\Progra~1\WinZip\wzzip.exe -m -ex" 'Path and options For compression
Public Const DEF_BACKUP_DIR = "C:\Your Folder\Backups"  ' Backup folder

Dim strName

' -- Start Script
Call Main()
                                                

' ////////////////////
' Sub Declaration
' ////////////////////
Sub Main()

On Error Resume Next       

Dim strBackupPath
Dim strOriginalPath
Dim FSO
Dim strYear 
Dim strMonth
Dim strDay
Dim strHour
Dim strMin  
Dim C

  C = Chr(34) ' variable for " (double quote)      

  Set FSO = CreateObject("Scripting.FileSystemObject")   
  ' -- Make sure theres a disk in the floppy drive

  ' -- Check to make sure backup folder is valid
  If FSO.FolderExists(DEF_BACKUP_DIR) Then 
    ' -- Make sure we have a drawing to save
    If Not IsDrawing Then
       ShowString "No current drawing" & DEF_CENTERED
       ' -- Bail
       Exit Sub                   
    End If


      ' -- Store current drawings name
      strOriginalPath = GetCurrentFileName 

      ' -- Format a time and date stamp and strip illegal chars
      strYear = Replace(FormatDateTime(Date, vbShortDate), "/", "")
      strHour = Replace(FormatDateTime(Time, vbShortTime), ":", "")
      

      ' -- Build fullpath
      strBackupPath = AddBackSlash(DEF_BACKUP_DIR) & FSO.GetBaseName(strOriginalPath) & "_" & strYear & "_" & strHour & "." & FSO.GetExtensionName(strOriginalPath)
      
      Call ClearMenuAndPrompts 
      
      ' -- Display current file in prompt area
      Call WriteString("Backing up file, please wait...")    
      
     
      If SaveMCAs(strBackupPath, True) Then

	  strName = strZipPath & " " & C & strBackupPath & ".zip" & C & " " & C & strBackupPath & C  

      Call ShellAndWait(strName, True)
'         ShowString "Backup to " & DEF_BACKUP_DIR & " complete" & DEF_CENTERED
      Else
         ShowString "Could not backup file to "  & DEF_BACKUP_DIR & DEF_CENTERED
      End If
      
      ' -- Switch back to original file   
      Call SaveMCAs(strOriginalPath, True) 
      Call ClearMenuAndPrompts

      Call RepaintScreen (True)

  Else
     ShowString "Folder " & DEF_BACKUP_DIR & " does not exist!" & DEF_CENTERED
     Exit Sub
  End If


  If Err Then Call TrapError("Sub::Main", Err, True)

 Set FSO = Nothing

End Sub 

' ////////////////////
' Sub Declaration
' ////////////////////
Sub TrapError(sSource, objErr, bLogIt)

     Dim sMSG
     Dim sLogError
     Dim FSO
  

    sMSG = "Following error occurred in this script:" & DEF_CENTERED & vbCrLf & vbCrLf
    sMSG = sMSG & objErr.Description & DEF_CENTERED & vbCrLf
    sMSG = sMSG & "Number: " & objErr.Number & DEF_CENTERED & vbCrLf
    sMSG = sMSG & "Source: " & DEF_CENTERED & sSource
    
    ShowString sMSG 

    
    If bLogIt Then
       
        sLogError = "Error " & objErr.Number & " in " & sSource & ":" & vbCrLf & objErr.Description
        Call WriteLog(sLogError)

    End If
    
    objErr.Clear

    Set objErr = Nothing

End Sub

                  
' ////////////////////
' Sub Declaration
' ////////////////////

' ////////////////////
' Function Declaration
' ////////////////////
Function GetScriptEngineInfo()

  On Error Resume Next

  Dim s
  s = ""                ' Build string with necessary info.
  s = ScriptEngine & " Version "
  s = s & ScriptEngineMajorVersion & "."
  s = s & ScriptEngineMinorVersion & "."
  s = s & ScriptEngineBuildVersion
  
  GetScriptEngineInfo = s   ' Return the results.

  If Err Then Call TrapError("GetScriptEngineInfo", Err, True)


End Function

' ////////////////////
' Function Declaration
' ////////////////////
Function CheckDrive(sPath)

On Error Resume Next

  Dim FSO
  Dim fsoDrive

  Set FSO = CreateObject("Scripting.FileSystemObject")
  
  ' -- Get the "A" drive
  Set fsoDrive = FSO.GetDrive(sPath)

  Select Case fsoDrive.DriveType
         ' -- Only interested in a Floppy drive...
         Case fsoDRIVE_REMOVABLE: CheckDrive = fsoDrive.IsReady
         Case Else
              ' -- Force failure
              CheckDrive = False
  End Select


' -- Clean up
Set FSO = Nothing
Set fsoDrive = Nothing

If Err Then Call TrapError("Function::CheckDrive", Err, True)


End Function


' ////////////////////
' Function Declaration
' ////////////////////

Function AddBackSlash(sPath)

If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
AddBackSlash = sPath

End Function


' ////////////////////
' Function Declaration
' ////////////////////

Function IsDrawing()

Dim Ret

Ret = StartDBSearch(mc_alive, -1)

IsDrawing = Ret

End Function
'Rekd teh sharing
__________________
Matt
San Diego, Ca

___ o o o_
[l_,[_____],
l---L - □lllllll□-
( )_) ( )_)--)_)

(Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

Last edited by Rekd; 07-16-2003 at 12:00 PM.
Reply With Quote

 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361