如何使用 C# 恢复 IIS 元数据库备份

发布于 2024-08-20 20:25:41 字数 690 浏览 10 评论 0原文

我发现 Stack Overflow 问题描述了如何在 C# 中备份 IIS Metabase 这里,我已经成功地使用引用的代码此处。但是,我在使用 C# 代码恢复这些备份(或者实际上在 IIS 中手动创建的任何备份)时遇到困难。

有谁知道如何做到这一点,或者是否可以做到?与备份本身不同,我在网上找不到任何这样的示例。

我已尝试以下代码,但收到错误'调用的目标已抛出异常'

using (DirectoryEntry localhostIIS = new DirectoryEntry("IIS://LocalHost"))
{
   localhostIIS.Invoke("Restore", new object[] { string.Empty, 0, 0});
}

现在,虽然我确定我正在使用错误的名称和/或调用该方法对象结构,我一直无法在任何地方找到调用它的正确方式......

任何人都可以指出我正确的方向吗?

I've found the Stack Overflow question describing how to backup the IIS Metabase in C# here, and I have been successful at getting that to work using the code referenced here. However, I am having difficulty restoring those backups (or indeed any backups created manually in IIS) using C# code.

Does anyone know how to do this, or even if it can be done? I haven't been able to find any examples of this on the web, unlike the backup itself.

I have tried the following code, but receive the error 'Exception has been thrown by the target of an invocation'

using (DirectoryEntry localhostIIS = new DirectoryEntry("IIS://LocalHost"))
{
   localhostIIS.Invoke("Restore", new object[] { string.Empty, 0, 0});
}

Now while I'm sure that I'm calling the method with the wrong name and/or object structure, I haven't been able to find the correct way of calling it anywhere....

Can anybody please point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下凄凉 2024-08-27 20:25:41

我尝试使用命名备份进行此操作,并通过一些调整使其正常工作:

const uint MD_BACKUP_HIGHEST_VERSION = 0xfffffffe;
const uint MD_BACKUP_NEXT_VERSION = 0xffffffff;
const uint MD_BACKUP_SAVE_FIRST = 2;

using(DirectoryEntry de = new DirectoryEntry("IIS://Localhost"))
{
  // Backup using the next version number (MD_BACKUP_NEXT_VERSION)
  de.Invoke("Backup", new object[] {
      "test-backup",
      MD_BACKUP_NEXT_VERSION,
      MD_BACKUP_SAVE_FIRST
  });

  // Restore the highest version number (or specify the specific version)
  de.Invoke("Restore", new object[] {
    "test-backup",
    MD_BACKUP_HIGHEST_VERSION,
    0
  });
}

I tried this with a named backup and got this to work with some tweaks:

const uint MD_BACKUP_HIGHEST_VERSION = 0xfffffffe;
const uint MD_BACKUP_NEXT_VERSION = 0xffffffff;
const uint MD_BACKUP_SAVE_FIRST = 2;

using(DirectoryEntry de = new DirectoryEntry("IIS://Localhost"))
{
  // Backup using the next version number (MD_BACKUP_NEXT_VERSION)
  de.Invoke("Backup", new object[] {
      "test-backup",
      MD_BACKUP_NEXT_VERSION,
      MD_BACKUP_SAVE_FIRST
  });

  // Restore the highest version number (or specify the specific version)
  de.Invoke("Restore", new object[] {
    "test-backup",
    MD_BACKUP_HIGHEST_VERSION,
    0
  });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文