Rename, Zip, Move All In Vbscript

Running a dedicated web server has taught me a lot, especially about backup and redundancy.

In the process of working through the best backup routines I had to develop a way to conserve some disk space and automate the movement and renaming of files around the server.  Having had a VB background I expected that VBScript would be the best option.

So below I have outlined the process (and scripts) I get my server to run every day to make manage these backup files.

Out of interest, I am using the Win 2003 backup service to do the backups, which basically puts a single file with all the incremental changes into a single location on the disk.  My objective was to rename the file, zip it and then move it to where I actually wanted it stored, ready for download in another automated FTP process each night.

Here’s the script, this script will:

‘ – Rename the latest backup file to format BYYYYMMDD.BAK
‘ – ZIP the above file to
‘ – Copy the file to /save
‘ – Delete the file from the current directorydim strDate
dim fso
dim objShell
dim strCommand
strDate = Year(Date()) & month(date()) & Day(Date())

set fso = CreateObject(”SCRIPTING.FileSystemObject”)

fso.MoveFile “c:\backup\backup.bkf”, “c:\backup\B” & strDate & “.bkf”

set objShell = WScript.CreateObject(”Wscript.Shell”)
strCommand = “””C:\program files\WinZip\wzzip.exe”” c:\backup\B” & strDate & “.ZIP c:\backup\B” & strDate & “.bkf” strCommand ,0 ,true

fso.MoveFile “c:\backup\B” & strDate & “.zip”, “c:\backup\save\B” & strdate & “.zip”
fso.DeleteFile “c:\backup\B” & strdate & “.bkf”

set fso = Nothing
set objShell = Nothing

Basically it does the following:

  1. Initiates some variables
  2. Puts today’s date into a formatted string (which becomes part of the file name)
  3. Using a File System Object (FSO) it renames the backup’d file to a file with the date in it
  4. It then executes a command line to zip the renamed file, and specifically waits until execution of this part is complete.
  5. Finally it moves the ZIP file to the new location (save directory) and deleted the original backup file

Looking at this again now (I wrote this about 14 months ago) there are more efficient ways to do this, however it does the job and has never once failed on me.