每夜备份服务模板 (脚本)

 

适用于: System Center 2012 R2 Virtual Machine Manager,System Center 2012 - Virtual Machine Manager

本主题中的脚本上的备份服务模板库中每晚定期通过导出的模板包。 有关演示如何使用导出的包到媒体库还原服务模板的示例脚本,请参阅 从以前的备份 (脚本) 导入服务模板时缺少

免责声明

通过使用任务计划程序计划任务

若要按计划运行脚本,您需要在 Windows 任务计划程序服务中创建一个任务。 您的任务中的操作必须开始 Powershell.exe,并加载 System Center 2012 – Virtual Machine Manager (VMM) 才能运行该脚本使用 VMM cmdlet 的模块。 下面的语法启动 Powershell.exe,加载 VMM 模块,然后运行名为 NightlyTemplateBackup.ps1 的脚本位于 C:\MyScripts 文件夹中︰

PowerShell.exe -NoExit ipmo virtualmachinemanager; C:\MyScripts\NightlyTemplateBackup.ps1

您可以设置为此操作,同时每一天,如下午 11:00 启动此进程的触发器。

以下脚本获取所有服务模板,创建一个文件夹用于存储导出的包,并随后会导出这些模板。

  
# Description:    This script backs up service templates from the library by  
#                 exporting the service templates to a file path.  
  
# Get all service templates.  
$ServiceTemplates = Get-SCServiceTemplate  
  
# Create a folder for today's backup.  
$Date = Get-Date -uformat "%Y_%m_%d"  
$Dir = New-Item -Type Directory -Path D:\TemplateExports\$Date  
$Path = $Dir.FullName  
  
# Export the service templates.  
Foreach ($Template in $ServiceTemplates)  
{  
   Export-SCTemplate -ServiceTemplate $Template -Path $Path -SettingsIncludePrivate  
}  
  

另请参阅

Get SCServiceTemplate
导出 SCTemplate