Back Up server data (IIS configuration, Task Scheduler, Service list, and app)

Source: Internet
Author: User
Tags schtasks

The script can be used to export IIS configurations, task schedules, service lists, and apps, while supporting Windows 2003 and 2008.

#Define Backup Location$iisfolder="D:\Backup_all\IIS"$taskfolder="D:\Backup_all\Task"$servicesfolder="D:\Backup_all\Service"$appfolder="D:\Backup_all\app"#define where the source app files are located$app _sourcefolder="D:\DDservice"#New FolderIf(! (Test-path$iisfolder) ) {mkdir$iisfolder}If(! (Test-path$taskfolder) ) {mkdir$taskfolder}If(! (Test-path$servicesfolder) ) {mkdir$servicesfolder}If(! (Test-path$appfolder) ) {mkdir$appfolder}#export a list of services$servicepath=$servicesfolder+"\services_list.txt"Get-service |ft Displayname,name,status-wrap | Out-file $servicepath#Backup App$CurrentPath=$MyInvocation. MyCommand.Path.substring (0,$MyInvocation. MyCommand.Path.LastIndexOf (' \ ') +1)$uncopyfile= Join-path$CurrentPath Backup_all_uncopy.txt$apppath=$appfolder+"\"xcopy/e/h/r/s/y/exclude:$uncopyfile $app _sourcefolder\*.*$apppath $Version= [System.Environment]::OSVersion.Version.MajorIf($Version -ne5){#To back up the IIS configuration, use the Appcmd Restore backup command to restore the IIS configuration: appcmd Restore Backup BackupName$iispath=$iisfolder+"\"New-alias-name Appcmd-value$env: windir\system32\inetsrv\appcmd.exeappcmd Add backupxcopy/s/y C:\Windows\System32\inetsrv\backup$iispath#Export a task schedule, use the Schtasks/create command to import a task plan$Schedule= new-object-com"Schedule.service"$Schedule. Connect ()$Schedules=$Schedule. GetFolder ("\"). Gettasks (0)If($TaskName -eq $null){  Foreach($task inch $Schedules)    {     $taskname=$task. Name$taskpath=$taskfolder+"\"+$taskname+". XML"cmd/C"chcp 437 >null && schtasks/query/xml one/tn""$taskname"" "|out-file $taskpath    }}}Else{#Backup Task Schedule, copy the backed up files to C:\WINDOWS\Tasks to complete the restore$taskpath=$taskfolder+"\"xcopy/s/y C:\WINDOWS\Tasks$taskpath#backing up the IIS configuration, using Iiscnfg/import to restore the IIS configuration#Example:cscript.exe c:\windows\system32\iiscnfg.vbs/import/f d:\i.xml/sp//children/d DD123/DP/$time= Get-date-uformat"%y%m%d%h%m"$iispath=$iisfolder+"\"+"iisconfig03_"+$time+". XML"cscript.exe C:\Windows\System32\iiscnfg.vbs/export/f$iispath/SP//CHILDREN/D DD123}

The backup_all_uncopy.txt file is placed in the same directory as the above script, which reads as follows:

\log\
\logs\

Back Up server data (IIS configuration, Task Scheduler, Service list, and app)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.