This is a very cool time saving ActiveX Script, run manually from within DTS Designer, that generates date and sequence named backups of the package into the specified development and backup folders. Don't ever lose work again.
This is a very cool time saving ActiveX Script, run manually from within DTS Designer, that generates date and sequence named backups of the package into the specified development and backup folders. Don't ever lose work again.
'************************************************************************ '* Fun with ActiveX Scripts '************************************************************************ '* Create and Manage Backups of a DTS Package From DTS Designer '************************************************************************ '* Author: '* Lane Tharp '* CountryWide Financial Services '* Performance Management Group '* Plano, Texas '* 2005/01/08 6:22 AM '* ------------------------------------------------------------------------------------------------- '* Description: '* - This script will create up to 52 backup files in development directory with date and '* alphabetic sequence naming. '* - This script will move backup history to another location for previous dates. '* ------------------------------------------------------------------------------------------------- '* Useage: '* 1. Add an ActiveX Script Task to Package being renamed in DTS Designer. '* 2. Disable this Task in workflow properties so it does not run with package. (Do not skip this step) '* 3. Copy this script into the ActiveX Task. '* 5. Make a backup copy of the package. (Do not skip this step) '* 6. Save the package. (Do not skip this step) '* 7. Execute only the ActiveX script in DTS Designer. '* 8. Check for backup files. '*------------------------------------------------------------------------------------- '* Debug Note: '* - This script is not intended for unnattended execution. '* - Do not edit scripts in the ActiveX Task Properties in DTS. (You will go blind.) '* - Edit as .vbs file in, and *debug* scripts in the Microsoft Script Editor. '************************************************************************ Function Main() On Error Resume Next Main = DTSTaskExecResult_Success ' Create Backup File If Not CreateBackup Then Main = DTSTaskExecResult_Failure End If End Function '************************************** '* Create and Manage Backups '************************************** Function CreateBackup() On Error Resume Next Dim fso Dim pkg Dim loFolder Dim loFiles Dim loFile Dim lsDate Dim lsYear Dim lsMonth Dim lsDay Dim lsBackupFileName Dim lsSequence Const lcDTSFolder = "C:\DTS\" Const lcDTSPackageName = "PaceSurvey_Update" Const lcBackupFolder = "C:\Backup\" Const lcExtension = ".dts" Const lbForce = True CreateBackup = True '---------------------- ' Open Debugger ' Stop '------------------- ' Get File System and Package Set fso = CreateObject("Scripting.FileSystemObject") Set pkg = DTSGlobalVariables.Parent If Err.Number <> 0 Then Msgbox Err.Description CreateBackup = False End If '<- Exit 1 If CreateBackup = True Then '------------------------- ' Format Backup Date lsYear = Year(Now) ' Get Year lsMonth = Month(Now) ' Get Month If Len(lsMonth) = 1 Then lsMonth = "0" & lsMonth ' Pad Month lsDay = Day(Now) ' Get Day If Len(lsDay) = 1 Then lsDay = "0" & lsDay ' Pad Day lsDate = lsYear & lsMonth & lsDay '------------------ ' Set Path Specs lsSequence = "a" lsBackupFileName = lcDTSFolder & lcDTSPackageName & lsDate & lsSequence & lcExtension If Err.Number <> 0 Then Msgbox Err.Description CreateBackup = False End If '<- Exit 2 If CreateBackup = True Then '---------------------------------------- ' Determine Next Backup File Name Do If Not fso.FileExists(lsBackupFileName) Then Exit Do lsSequence = GetSequence(lsSequence) ' Fail on error or more than 52 backups (Come on now) If lsSequence = "Max" _ Or Err.number <> 0 Then CreateBackup = False Exit Do End If lsBackupFileName = lcDTSFolder & lcDTSPackageName & lsDate & lsSequence & lcExtension Loop '<- Exit 3 If CreateBackup = True Then '--------------------------------------------- ' Backup Existing Structured Object File lsFileName = lcDTSFolder & lcDTSPackageName & lcExtension If fso.FileExists(lsFileName) Then ' Backup Current File and Save To Object File fso.CopyFile lsFileName, lsBackupFileName fso.DeleteFile lsFileName, lcForce pkg.SaveToStorageFile lsFileName Else ' Create Structured Object File pkg.SaveToStorageFile lsFileName End If '----------------------------------------- ' Move Old Backups to repository ' Get Folder Set loFolder = fso.GetFolder(lcDTSFolder) ' Get Files Collection Set loFiles = loFolder.Files ' Loop Through Files For Each loFile In loFiles ' File for this package If InStr(loFile.Name, lcDTSPackageName) <> 0 Then ' Not Main Object Filevoid Master Object File If loFile.Name <> lcDTSPackageName & lcExtension Then ' Backup File From Another Date If InStr(loFile.Name,lsDate) = 0 Then loFile.Move lcBackupFolder End If End If End If Next '<- Exit 3 End If '<- Exit 2 End If '<- Exit 1 End If ' Destroy Objects Set fso = Nothing Set pkg = Nothing Set loFolder = Nothing Set loFiles = Nothing Set loFile = Nothing End Function '*********************************** '* Generate Alphabetic Naming Sequence '*********************************** Function GetSequence(lsOldSequence) On Error Resume Next Select Case lsOldSequence Case "a" GetSequence = "b" Case "b" GetSequence = "c" Case "c" GetSequence = "d" Case "d" GetSequence = "e" Case "e" GetSequence = "f" Case "f" GetSequence = "g" Case "g" GetSequence = "h" Case "h" GetSequence = "i" Case "i" GetSequence = "j" Case "j" GetSequence = "k" Case "k" GetSequence = "l" Case "l" GetSequence = "m" Case "m" GetSequence = "n" Case "n" GetSequence = "o" Case "o" GetSequence = "p" Case "p" GetSequence = "q" Case "q" GetSequence = "r" Case "r" GetSequence = "s" Case "s" GetSequence = "t" Case "t" GetSequence = "u" Case "u" GetSequence = "v" Case "v" GetSequence = "w" Case "w" GetSequence = "x" Case "x" GetSequence = "y" Case "y" GetSequence = "z" Case "z" GetSequence = "za" Case "za" GetSequence = "zb" Case "zb" GetSequence = "zc" Case "zc" GetSequence = "zd" Case "zd" GetSequence = "ze" Case "ze" GetSequence = "zf" Case "zf" GetSequence = "zg" Case "zg" GetSequence = "zh" Case "zh" GetSequence = "zi" Case "zi" GetSequence = "zj" Case "zj" GetSequence = "zk" Case "zk" GetSequence = "zl" Case "zl" GetSequence = "zm" Case "zm" GetSequence = "zn" Case "zn" GetSequence = "zo" Case "zo" GetSequence = "zp" Case "zp" GetSequence = "zq" Case "zq" GetSequence = "zr" Case "zr" GetSequence = "zs" Case "zs" GetSequence = "zt" Case "zt" GetSequence = "zu" Case "zu" GetSequence = "zv" Case "zv" GetSequence = "zw" Case "zw" GetSequence = "zx" Case "zx" GetSequence = "zy" Case "zy" GetSequence = "zz" Case Else GetSequence = "Max" '<-- Invalid Characters to cause error End Select End Function