Rekd
07-16-2003, 12:53 PM
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.
'////////////////////////////////////////////////////////////////////////////////
'//
'// 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
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.
'////////////////////////////////////////////////////////////////////////////////
'//
'// 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