備份伺服器資料(IIS配置、任務計劃、服務列表和APP)

來源:互聯網
上載者:User

標籤:

該指令碼可以用來匯出IIS配置、任務計劃、服務列表和APP,同時支援Windows 2003和2008。

#定義備份位置$iisfolder = "d:\Backup_all\IIS"$taskfolder = "d:\Backup_all\Task"$servicesfolder = "d:\Backup_all\Service"$appfolder = "d:\Backup_all\app"#定義源應用檔案所在位置$app_sourcefolder = "D:\DDservice"#建立檔案夾If (!(Test-Path $iisfolder)){mkdir $iisfolder}If (!(Test-Path $taskfolder)){mkdir $taskfolder}If (!(Test-Path $servicesfolder)){mkdir $servicesfolder}If (!(Test-Path $appfolder)){mkdir $appfolder}#匯出服務列表$servicepath = $servicesfolder + "\services_list.txt"Get-Service |ft DisplayName,Name,Status -Wrap |Out-File $servicepath#備份應用$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 -ne 5){#備份IIS配置,使用 appcmd restore backup 命令可以還原IIS配置:appcmd restore backup backupname$iispath08 = $iisfolder + "\"New-Alias -name appcmd -value $env:windir\system32\inetsrv\appcmd.exeappcmd add backupxcopy /s /y C:\Windows\System32\inetsrv\backup $iispath08#匯出任務計劃,使用schtasks /create 命令可以匯入任務計劃$Schedule = New-Object -com "Schedule.Service"$Schedule.Connect()$Schedules08 = $Schedule.GetFolder("\").GetTasks(0)If ($TaskName -eq $null){  Foreach ($task08 in $Schedules08)    {     $taskname08=$task08.name     $taskpath08 = $taskfolder + "\" + $taskname08 + ".xml"     cmd /c "chcp 437 >null && schtasks /query /xml ONE /tn ""$taskname08"" " |out-file $taskpath08    }}}Else{#備份任務計劃,將備份的檔案拷貝到 C:\WINDOWS\Tasks 即可完成還原$taskpath03 = $taskfolder + "\" xcopy /s /y C:\WINDOWS\Tasks $taskpath03#備份IIS配置,使用 iiscnfg /import 可以還原IIS配置#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"$iispath03 = $iisfolder + "\" + "iisconfig03_" + $time + ".xml"cscript.exe C:\Windows\System32\iiscnfg.vbs /export /f $iispath03 /sp / /children /d dd123}

Backup_all_uncopy.txt檔案與上面指令碼放在同一個目錄下,該指令碼內容如下:

\log\
\logs\

備份伺服器資料(IIS配置、任務計劃、服務列表和APP)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.