Backup Script..


Results 1 to 4 of 4

Thread: Backup Script..

  1. #1
    Registered Rekd's Avatar
    Join Date
    Apr 2003
    Location
    teh Debug Window
    Posts
    1876
    Downloads
    0
    Uploads
    0

    Default 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

    Similar Threads:
    Last edited by Rekd; 07-16-2003 at 01:00 PM.
    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)


  2. #2
    Registered CAMmando's Avatar
    Join Date
    May 2003
    Location
    Phila PA, USA
    Posts
    146
    Downloads
    0
    Uploads
    0

    Default

    Now Rekd ...

    How ya ever gonna get that cnc router project going if yer spending all your time hax'in in VB Script ?



    Cool script BTW

    Dave teh "sexually aroused over used servos and ball screws ... Im starting to get woried here"

    Wee aim to please ... You aim to ... PLEASE.


  3. #3
    Registered Rekd's Avatar
    Join Date
    Apr 2003
    Location
    teh Debug Window
    Posts
    1876
    Downloads
    0
    Uploads
    0

    Default

    Originally posted by CAMmando
    Now Rekd ...

    How ya ever gonna get that cnc router project going if yer spending all your time hax'in in VB Script ?



    Cool script BTW

    Dave teh "sexually aroused over used servos and ball screws ... Im starting to get woried here"
    Um, yeah, well.. um... yeah.

    Imma need to spend about 3 months cleaning out the garage in order to get it ready... Any volunteers wanna help?

    'Rekd teh Free Rum & Coke!

    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)


  4. #4
    Registered Rekd's Avatar
    Join Date
    Apr 2003
    Location
    teh Debug Window
    Posts
    1876
    Downloads
    0
    Uploads
    0

    Thumbs up Update to Archiver.VBS Script

    I changed it a bit so now when it finds an already existing archive
    with that file name, it will add to it instead of creating a new one.
    (All parts with same name will be in 1 .zip file now)

    Enjoy!

    Code:
    '////////////////////////////////////////////////////////////////////////////////
    '//
    '//        Author:   Matt Finley
    '//                  Original script by Mick George.
    '//          Date:   11/09/2003 07:31 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 at: http://www.winzip.com/wzcline.cgi
    '//
    '//      Comments:   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. This version will group all files with
    '//                  the same name into the same .zip file. (Bigger zip files, less
    '//                  wasted space and less clutter. 
    
    
    '    -----------------                                                       
    '   | Constants      |                                                       
    '    ------------------------------------------------------------------------
    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 strBackupPath
    Dim strOriginalPath  
    Dim strFilePath
    Dim FSO  
    Dim strYear 
    Dim strMonth
    Dim strDay
    Dim strHour
    Dim strMin  
    Dim C
    Dim strName
           
    C = Chr(34) ' holder for " (double quote)      
    
    Call Main()
    
    Sub Main()
                Call RepaintScreen (True)
    On Error Resume Next       
          ' -- Check to make sure backup folder is valid
          Set   FSO = CreateObject("Scripting.FileSystemObject")   
          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 drawing's name
                strOriginalPath = GetCurrentFileName 
                ' -- Format a time and date stamp and strip illegal chars
                strYear = Replace(FormatDateTime(Date, vbShortDate), "/", "")
                strHour = Replace(FormatDateTime(Time, vbShortTime), ":", "")
                ' -- Build path for the MC9 file name with date/time stamp added
                strBackupPath = AddBackSlash(DEF_BACKUP_DIR) & FSO.GetBaseName(strOriginalPath) & "_" & strYear & "_" & strHour & "." & FSO.GetExtensionName(strOriginalPath)
                ' -- Build path for .ZIP file, (MC9 file name without date/time stamp, reduces clutter)
                strFilePath = AddBackSlash(DEF_BACKUP_DIR) & FSO.GetBaseName(strOriginalPath) & ".zip"
                Call ClearMenuAndPrompts 
                ' -- Display current file in prompt area
                Call WriteString("Backing up file, please wait..." & strBackupPath)    
                ' -- Save current file with new name and continue
                If SaveMCAs(strBackupPath, True) Then 
                      ' -- Build the command string for zipping (I'm having to truncate the exe's path, and
                      ' --  quote the zip name and file name, go figure..)
                      strName =   strZipPath & " " & C & strFilePath & C & " " & C & strBackupPath & C  
                      ' -- Fire the zipping event
                Call WriteString("Creating .zip file. Please wait..." & strFilePath)    
                Call ShellAndWait(strName, True)
                      ' -- Error?
                Else
                      ShowString  "Could not backup file to "  & DEF_BACKUP_DIR & DEF_CENTERED
                End If
                ' -- Switch back to original file   
                Call SaveMCAs(strOriginalPath, True) 
                ' --  Clean up
                Call ClearMenuAndPrompts
                Call RepaintScreen (True)
          Else
                ' -- Folder error. DOH!
                ShowString "Folder      " & DEF_BACKUP_DIR & " does not exist!" & DEF_CENTERED
                Exit Sub
          End   If                                              
                ' -- Generate error message and clean up
          If Err Then Call TrapError("Sub::Main",   Err, True)
          Set FSO = Nothing
    End Sub 
    
    '    -----------------                                                       
    '   | Catch Errors  |                                                        
    '    ------------------------------------------------------------------------
    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
    
    '    ----------------                                                        
    '   | Script Engine |                                                        
    '    ------------------------------------------------------------------------
    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
    
    '    ----------------                                                        
    '   | Add Backslash |                                                        
    '    ------------------------------------------------------------------------
    
    Function AddBackSlash(sPath)
          If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
          AddBackSlash = sPath
    End Function
    
    '    -----------------                                                       
    '   | Drawing exists? |                                                      
    '    ------------------------------------------------------------------------
    Function IsDrawing()
          Dim Ret
          Ret = StartDBSearch(mc_alive, -1)
          IsDrawing = Ret
    End Function
    'Rekd

    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)


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

Backup Script..

Backup Script..