スクリプトを作成しないのはなぜですか?ここに私が使用する小さなスクリプトがあります:
[System.Console]::Clear()
write-host "remoting to live environment"
$siteCollectionUrl = "http://live.mysite.com";
if ($args.count -gt 0) {
$siteCollectionUrl = $args[0]
write-host "going to pullback content from $siteCollectionUrl"
}
$pwd = Get-Content c:\install\backups\crd-sharepoint.txt | ConvertTo-SecureString
$crd=new-object -typename System.Management.Automation.PSCredential -ArgumentList "dev\svc-sp-setup-dvt", $pwd
$s = New-PSSession -computername "liveServer" -Authentication CredSSP -Credential $crd
Invoke-Command -Session $s -Scriptblock {
param($siteCollectionUrl)
write-host "Connected, activating SharePoint snap-in..."
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction "SilentlyContinue"
write-host "Backing up $siteCollectionUrl remotely..."
backup-spsite -identity "$siteCollectionUrl" -path "c:\install\backups\scheduled_backup.bak" -force
} -args $siteCollectionUrl
#end session
Remove-PSSession $s
$path = "c:\install\backups\"
write-host "Copy backup locally..."
#copy
copy-item "\\liveServer\c$\install\backups\scheduled_backup.bak" $path -Force
write-host "restore...this may take a while if not already running in SharePoint PowerShell. your patience is appreciated"
#restore
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
restore-spsite -identity "$siteCollectionUrl" -path c:\install\backups\scheduled_backup.bak -force -confirm:$false
$username = [Environment]::UserName
write-host "have a great day, $username"
これには、PowerShell リモート処理を有効にする必要があります。サイトのリストがある場合は、コピーしたいサイト コレクションの URL を指定してこのスクリプトを繰り返し呼び出すことができます。
$scriptPath = Join-Path (get-location) "backup_and_restore.ps1";
& $scriptPath "http://admin.accounting.mycompany.com"
& $scriptPath "http://admin.sales.mycompany.com"
& $scriptPath "http://admin.marketing.mycompany.com"
& $scriptPath "http://admin.engineering.mycompany.com"
または、スクリプトでサイト コレクションごとにバックアップを作成し、それらを同じように復元することもできます。これは、SharePoint スナップインを再起動する必要がないため、劇的に効率的になりますが、状況に応じて何が最適かを判断するのはあなた次第です。