Results 1 to 4 of 4

Thread: IIS backup C#

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    19

    Question IIS backup C#

    Dear Friends,

    How to Backup IIS 6.0 using C#.
    Any Peice of information is appreciatable..


    Manu

  2. #2
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: IIS backup C#

    ...use ntbackup and schedule a job. No c# code is needed.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    19

    Re: IIS backup C#

    but i my requirement is not a scheduled one

  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: IIS backup C#

    You've already been given the link to Microsoft's documentation on the IIS ADSI provider.

    So, using the link provided here, I managed to find the IIsComputer.Backup documentation.

    Now, using my understanding of the ADSI provider - which you should have as well, seeing as you've apparently written code that creates virtual directories - I wrote this class:

    Code:
    public sealed class Iis
    {
    	/// <summary>
    	/// Forces the backup to proceed even if the save fails. Only valid if MD_BACKUP_SAVE_FIRST is specified.
    	/// </summary>
    	public const uint MD_BACKUP_FORCE_BACKUP = 0x00000004;
    	/// <summary>
    	/// Backs up the metabase even if a backup with the same name and version already exists, overwriting the existing files.
    	/// </summary>
    	public const uint MD_BACKUP_OVERWRITE = 0x00000001;
    	/// <summary>
    	/// Saves the metabase prior to making the backup. Specify MD_BACKUP_FORCE_BACKUP if you want the backup 
    	/// to proceed even if the save fails.
    	/// </summary>
    	public const uint MD_BACKUP_SAVE_FIRST = 0x00000002;
    	/// <summary>
    	/// Automatically selects the next available version number
    	/// </summary>
    	public const uint MD_BACKUP_NEXT_VERSION = 0xffffffff;
    	
    	/// <summary>
    	/// The DirectoryEntry method name for the backup procedure.
    	/// </summary>
    	private const string METHOD_BACKUP = "Backup";
    	
    	public Iis()
    	{
    	}
    	
    	/// <summary>
    	/// Backups the local IIS server's metabase.
    	/// </summary>
    	/// <param name="location">String containing the location. If an empty string is specified, the default backup location will be used. IIS determines the backup storage mechanism, so the backup location name you provide does not necessarily translate to a particular directory, file, or database storage mechanism. Metabase backups are stored as files in the system32\inetsrv\MetaBack directory</param>
    	/// <param name="version">Long integer containing the version number to be assigned to the backup. Must be less than or equal to 9999. Can be set to <see "MD_BACKUP_NEXT_VERSION" /> (0xffffffff) which automatically selects the next available version number.</param>
    	/// <param name="backupFlags">Long integer containing one or more of the following flags:
    	/// <para><see cref="MD_BACKUP_FORCE_BACKUP"/> (0x00000004) forces the backup to proceed even if the save fails. Only valid if MD_BACKUP_SAVE_FIRST is specified.</para>
    	/// <para><see cref="MD_BACKUP_OVERWRITE"/> (0x00000001) backs up the metabase even if a backup with the same name and version already exists, overwriting the existing files.</para>
    	/// <para><see cref="MD_BACKUP_SAVE_FIRST"/> (0x00000002) saves the metabase prior to making the backup. Specify MD_BACKUP_FORCE_BACKUP if you want the backup to proceed even if the save fails.</para>
    	/// </param>
    	public void BackupIis(string location, uint version, uint backupFlags)
    	{
    		using (DirectoryEntry localhostIIS = new DirectoryEntry("IIS://LocalHost"))
    		{
    			localhostIIS.Invoke(METHOD_BACKUP,
    				                new object[]
    				                    {
    				                    	location,
    				                    	version,
    				                    	backupFlags
    				                    });
    		}
    	}
    }
    Which is used thus:
    Code:
    Iis myIis = new Iis();
    myIis.BackupIis(string.Empty,
    				Iis.MD_BACKUP_NEXT_VERSION,
    				Iis.MD_BACKUP_SAVE_FIRST | Iis.MD_BACKUP_FORCE_BACKUP);
    Next time, please try this yourself before asking everyone else to do so for you.

Posting Permissions

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



Click Here to Expand Forum to Full Width