Backing up the IIS metabase
I'm aware that most of the audience here consider IIS as some sort of swearword, but if you ever do come across an NT box running IIS the following VERY simple script can be quite useful.
Overview
The IIS metabase is a hived datastore similar to the windows registry. It contains all the information about the sites stored within your IIS configuration.
As part of your disaster recovery program you should do regular backups of this metabase. The metabase backups from this script are created in c:\winnt\system32\inetsrv\metaback where c:\winnt is the path to your o/s installation.
I wanted to automate the process. I am always willing to spend an few hours today to save myself a 5 miniutes a week for the rest of my life. I figure if I do enough of that sort of thing now then by the time I'm 50 I'll have accrued enough extra time to have a social life (but I'm not holding my breath :)) If I save 5 minutes of your life don't forget my greens ;)
I also wanted the script to delete the great-grandfather backup, so as to only ever maintain three generations of backup - Grand Father, Father and Son. As the script runs every seven days I can just delete the backup from 21 days ago so I always have todays backup, the one from 7 days ago and the one from 14 days ago. You can of course edit this as you wish.
Usage
This is a WSH script, so save it in a text file with a .vbs extention. To run it from a Win32 box you would go to the command prompt and type:
Quote:
cscript [drive]:\[path]\[filename.vbs]
The cscript part of the line tells windows to execute this from the console, rather that running via windows. You can change the default script host to CScript.exe using the command
Quote:
cscript //H:CScript
You can schedule this script using the AT command.
The code!
Code:
Dim currentobj
bkupName = "iis_" & dAY(DATE) & "-" & month(date) & "-" & year(date)
Set currentobj=GetObject("IIS://localhost")
currentobj.Backup bkupName, &HFFFFFFFF, "1"
set currentobj = nothing
Set fso = CreateObject("Scripting.FileSystemObject")
fso.deleteFile("c:\winnt\system32\inetsrv\metaback\iis_"& _
dAY(DATE-21)&"-"& month(date-21) &"-"& year(date-21) &".md0")
set fso = nothing
If you found this article useful you may also enjoy these others:
Building your own IDS tripwire.
Credit card security
Dumping SQL data to a text file
Hunting down skript kiddies
Search Engine submission 'exploit'
Forced shutdown of a remote nt/2k server
Securing an installation of IIS 4. (No, seriously)
Remote DSN Connections, using WinAPIs and the registry
Scripting Internet Connections Under Window$