Internet Information Services 7 (IIS7) stores its configuration in ApplicationHost.config along with associated schema files rather than the metabase used by IIS6. The provided script creates timestamped backups via the appcmd utility. Run it from an elevated command prompt to capture all server settings, sites, application pools, and global configuration in a recoverable format.
Regular backups protect against configuration drift, failed updates, or accidental changes that could take a web server offline. This process ensures you can restore a known-good state quickly. The script below generates a unique backup name based on date and time, avoiding overwrites and maintaining a history of configurations.
#IIS7 Configuration Storage Explained
Unlike IIS6 which used a metabase-like file, IIS7 and later versions use a distributed XML-based configuration system. The primary file is ApplicationHost.config located under C:\Windows\System32\inetsrv\config. This file defines every aspect of your web server including sites, virtual directories, application pools, modules, and security settings. Schema files in the same directory define the allowed structure and defaults. Because of these changes, IIS6 backup tools cannot read or preserve IIS7 settings. Backing up correctly requires using the native appcmd.exe tool to export a complete snapshot.
#Creating the Backup Script
Using notepad or any text editor create a file backupiis7.cmd. The script navigates to the inetsrv directory, constructs a timestamp from the current date and time, then invokes appcmd to create the backup. It cleans up after itself to avoid leaving temporary files.
Insert the following code and save the file:
@echo off
cls
pushd "%WinDir%\System32\inetsrv"
echo.| date | find /i "current">datetime1.tmp
echo.| time | find /i "current">datetime2.tmp
for /f "tokens=1,2,3,4,5,6" %%i in (datetime1.tmp) do ( echo %%n>datetime1.tmp )
for /f "tokens=1,2,3,4,5,6" %%i in (datetime2.tmp) do ( echo %%m>datetime2.tmp )
for /f "delims=/ tokens=1,2,3" %%i in (datetime1.tmp) do ( set TMPDATETIME=%%k%%i%%j )
for /f "delims=:. tokens=1,2,3,4" %%i in (datetime2.tmp) do ( set TMPDATETIME=D%TMPDATETIME%T%%i%%j%%k%%l )
appcmd add backups %TMPDATETIME%
del datetime1.tmp
del datetime2.tmp
set TMPDATETIME=
popd
echo.
Save the completed file to a permanent scripts directory such as C:\Admin\Scripts. This keeps it available for manual runs or scheduled tasks. The generated backup name follows the pattern DYYYYMMDDTHHMMSS, ensuring each backup is uniquely identified.
#Executing the Backup and Locating Files
Run the script from an elevated Command Prompt. Navigate to the folder containing backupiis7.cmd and execute it directly. The IIS7 configuration will be backed up at the following path: C:\Windows\System32\inetsrv\backup. Each backup appears as a subfolder named with the timestamp generated by the script. Inside the folder you will find copies of applicationHost.config, administration.config, and redirection.config. Use the command "appcmd list backups" from the inetsrv directory to see all available backups with their creation dates.
#Automating Backups with Task Scheduler
You can also use Task Scheduler to automate backups. Create a task that runs the backupiis7.cmd file on a daily or weekly schedule, ideally during off-peak hours. This removes the risk of forgetting manual backups before maintenance windows. When creating the task, specify the full path to the CMD file, set it to run whether the user is logged on or not, and enable "Run with highest privileges" so appcmd executes correctly.
Common pitfalls include running the script without administrative rights, which causes access-denied errors from appcmd, and locale-specific date formats that can break the parsing logic in the batch file. Always test the script immediately after creation. Verify success by checking that a new timestamped folder appears in the backup directory and contains valid configuration files.
#Practical Takeaway
Run this backup before every configuration change and incorporate it into your disaster-recovery plan. Combine it with regular file-level backups of the entire inetsrv\config directory. To restore a backup, use the command "appcmd restore backup <timestamp>" from the same inetsrv directory. Test restores periodically in a non-production environment to confirm your process works when needed.
Comments
No comments yet