Results 1 to 10 of 10

Thread: Backing up the IIS metabase

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    324

    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:

    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

    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$
    \"I may not agree with what you say, but I will defend to the death your right to say it.\"
    Sir Winston Churchill.

  2. #2
    AO Antique pwaring's Avatar
    Join Date
    Aug 2001
    Posts
    1,409
    Do you have some insider knowledge as to how IIS works or something? Nice tutorial by the way, shame I use Apache though.
    Paul Waring - Web site design and development.

  3. #3
    Junior Member
    Join Date
    Jun 2002
    Posts
    3
    Yes. its cleared a few things up. Thanks for that. Hopefully newbies like myself will pick up on these handy tutorials and learn something.

  4. #4
    Hey pwaring, he has an MIS degree(I think). Lol, so does my sister, but she doesn't even like computers.

  5. #5
    Senior Member
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    734
    He has some degree to do with database programming or something like that...
    Another k3w1 tutorial ntsa

  6. #6
    Senior Member
    Join Date
    Apr 2002
    Posts
    324
    Well - Business informations Systems actually, but I've never been one to split hairs If you're interested in a little background on me have a look at www.ntsa.org.uk

    PS - khakisrule > Is she cute? (j/k - I'm married )
    \"I may not agree with what you say, but I will defend to the death your right to say it.\"
    Sir Winston Churchill.

  7. #7
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    Unfortunately this technique is totally useless for disaster recovery, as if your machine is trashed, the backup cannot be restored onto another machine (or the same one following a reformat).

    If you don't believe me, read the M$ docs. I didn't believe those so I tried it. It didn't work.

    There are some 3rdparty tools which claim to be able to backup the metabase in a way which is portable to other machines - maybe they work but I'd still rather settle for an entirely scripted and reproducable configuration any day.

    The IIS metabase is a case of M$ trying to make their product easier to use (than Apache) and actually succeeding in making it harder to use (Because the config is stored in an opaque binary format which cannot be backed up, restored, migrated or viewed easily)

    Fortunately they've learnt their lessons, and in Whistler, IIS6 will use a text (XML) file.

  8. #8
    Senior Member
    Join Date
    Apr 2002
    Posts
    324
    Slarty >

    Unfortunately this technique is totally useless for disaster recovery
    That's not quite true. I have in fact written a script that uses the md0 backup file created by this script to rebuild IIS on a re-preped machine. Unfortunately this code is proprietary and is one of the bits of code that pays my wages, so I can't post it.

    So a word to the wise - hacking (and I mean it here in the Eric S Raymond sense of the word) begins where the documentation ends. I have spent most of my working career getting Microsoft products to do more than their documentation would suggest and am here to tell you, don't believe everything you read - especially in the M$ propoganda sheets.

    Still, you seem like a bright lad - I'm sure you can figure it out for yourself. Otherwise, as you rightly suggest, you can go right ahead and upgrade to IIS6.
    \"I may not agree with what you say, but I will defend to the death your right to say it.\"
    Sir Winston Churchill.

  9. #9
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    ntsa,

    Well done your metabase restore program is obviously cleverer than I have been able to achieve.

    I did try doing a backup/restore using the IIS tool (rightclick menu in the mmc), and manually copying the md0 backup file from one box to another, and it failed miserably to work, so I'm only speaking from experience. Also the docs said it was impossible (you obviously proved that the allegedly impossible is sometimes possible)

    Perhaps your re-preped machine was sufficiently similar to the original to persuade it to work.

  10. #10
    Senior Member
    Join Date
    Apr 2002
    Posts
    324
    _EXACTLY_ the same spec - all of our racks are. But I think your problem may have been more related to the layout of the hard drive (and that's a BIG hint).

    =]
    \"I may not agree with what you say, but I will defend to the death your right to say it.\"
    Sir Winston Churchill.

Posting Permissions

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