- 本站大部分内容从网上收集,收集目的仅供研究、学习。涉及版权或不希望收录您的文章请您及时与我联系。
- 本站IM群,请自行选择。请各位朋友按照自己喜好加入。加入群后请及时发言,防止被清理。谢谢您的合作!!!
- QQ群:Y①WEB开发(ASP.NET)号码:7351660 QQ群:Y②WEB开发(ASP+.NET)号码:11864905
- QQ群:Y③WEB开发(DIV+CSS)号码:16610506 QQ群:Y④WEB开发(JS+AJAX)号码:16143998
- QQ群:Y⑤WEB开发(新手)号码:12777715 MSN群:yaosansi[at]126.com
在%systemdrive%\windows\system32\inetsrv\下应该有个工具--Appcmd.exe,我们将使用该工具进行IIS7的备份及恢复。
备份
>AppCmd Add Backup "BackupName"
罗列备份
>AppCmd List Backup
恢复
>AppCmd Restore Backup "BackupName"
参考:http://mvolo.com/blogs/serverside/archive/2007/03/18/Most-Important-AppCmd-Commands_3A00_-Backing-up-and-restoring-IIS7-configuration.aspx
Most Important AppCmd Commands: Backing up and restoring IIS7 configuration
Welcome to the first post of the "Most Important AppCmd Commands" series. Have you ever made some changes to a system's state, and then after everything suddenly stopped working, wondered how the hell you are going to get back to a working state? Well, this post is all about doing just that when you are working with IIS7's configuration.
Usually, the state of the IIS7 server is comprised of the following things: 1) the installed IIS7 files managed by Windows setup, 2) the IIS7 configuration, and 3) your application files. The first is protected by System File Protection, so its not easy to accidentally mess up, and can be restored by using Windows setup. The application files are your own, and one would expect to have a backup of these somewhere so that you can recover from making unintended changes to them on the server.
The IIS7 configuration is our focus here, because its something that is frequently modified by different components during their installation, or by you in order to configure your application to behave in the specific way you need. In previous versions of IIS, this configuration was stored exclusively in the metabase, which was first a binary (IIS 4) and then an XML (IIS5-6) file in the %windir%\system32\inetsrv directory. With IIS7, even though most configuration can be stored in the distributed web.config files within the application hierarchy, and therefore can be backed up with the application itself, a number of settings still need to be stored in a central server configuration file, called applicationHost.config. This file contains the site/application/virtual directory/application pool definitions, and the default configuration settings for all sites on the machine.
As such, any time you create / delete sites or applications, or set global configuration on the server, applicationHost.config is modified. If you accidentally make changes to this file that cause undesired behavior, you will often want to restore a previous known-good version of this file instead of trying to modify the file piece by piece to get back to a good state.
To enable this, AppCmd.exe provides the BACKUP object that allows you to easily back-up, and restore the global server configuration. To get more information about the commands of the BACKUP object, type in: AppCmd backup /?
1) Creating a backup
To create a backup, simply type in:
>AppCmd Add Backup "BackupName"
You can omit the name, in which case AppCmd is going to generate the backup name automatically using the current date and time. When a backup is created, the following happens:
- A directory with the backup name is created under the %windir%\system32\inetsrv\backup directory.
- AppCmd copies the current configuration files into the backup directory, including applicationHost.config (IIS global configuration), administration.config (Admin Tool's configuration), metabase.xml and mbschema.xml. The last two files contain the metabase data that is still used by some IIS services including SMTP and FTP, that have not been migrated to the new configuration system. AppCmd only backs up the files that are there, so if you delete any of these files, and then make a backup, the backup will not contain the missing files.
2) Managing existing backups
To list the backups that exist on the server, type in:
>AppCmd List Backup
This will list the backup objects, including their names that can be used to restore or delete them. To delete any of these backups if its no longer needed, type in:
>AppCmd List Backup "BackupName"
3) Restoring a backup
To restore a backup, type in:
>AppCmd Restore Backup "BackupName"
This will stop IIS (equivalent to calling IISRESET.EXE /STOP), and overwrite the server's state with the files in the specified backup directory. Then, IIS will be re-started (equivalent to calling IISRESET.EXE /START).
If you do no want AppCmd to stop IIS (which can take a while), and instead want to stop and start services yourself, you can include the /stop:false parameter. Typically, only the IISADMIN service requires to be stopped so that the mbschema.xml file can be restored, if services like FTP or SMTP are being used. Other files, including applicationHost.config and administration.config, are not locked by the configuration system so they can be restored without stopping IIS, and IIS components will pick up the changes.
I recommend that you make backups every time before making significant changes to the IIS7 configuration, which can save you a lot of time when something doesnt go as planned. I've watched "AppCmd Restore Backup" come to the rescue more times then I can count, so its almost always the first thing that I do when I begin working with a new server, or help someone on the team investigate an issue.
In Windows Server "Longhorn" beta 3, we are adding a Configuration History service that automatically makes configuration backups every 2 minutes whenever configuration is changed. This often eliminates the need to do manual backups, but not completely - often its desireable to make a backup at a specific point before making changes, so that that exact state is saved and can be restored at any point. More info on the Configuration History service in a future post ...
订阅本站,阅读更多文章