Dear Friends,
How to Backup IIS 6.0 using C#.
Any Peice of information is appreciatable..
Manu
Printable View
Dear Friends,
How to Backup IIS 6.0 using C#.
Any Peice of information is appreciatable..
Manu
...use ntbackup and schedule a job. No c# code is needed.
but i my requirement is not a scheduled one
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:
Which is used thus: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
});
}
}
}
Next time, please try this yourself before asking everyone else to do so for you.Code:Iis myIis = new Iis();
myIis.BackupIis(string.Empty,
Iis.MD_BACKUP_NEXT_VERSION,
Iis.MD_BACKUP_SAVE_FIRST | Iis.MD_BACKUP_FORCE_BACKUP);