Hi
I use App Volumes in our VDI environment, and if you aren't aware can use vmdk files to store the application. These are not associated with any VM until they are needed. Currently I have a powercli script download the file from vcenter and the upload it to the other one. This was because in 5.5 it wasn't possible to use the ps-drives between vcenters. I was going to look into this again and wanted to see if there was a better option. Here is how I'm doing it now, which uses a csv file to make sure the files get where they need to, but is basically a recursive copy of the entire datastore.
function Recusive2VcenterDSCopy
{
param([string]$ItemPath,
[string]$TargetPath)
$datastoreitems = Get-ChildItem -path $ItemPath
foreach ($dsItem in $datastoreitems )
{
if($dsItem.ItemType -eq "Folder")
{
$foldername=$ItemPath+"\"+$dsItem.Name
$targetfoldername=$TargetPath+"\"+$dsItem.Name
$localname="C:\Scripts\appvolsync\"+$dsItem.Name
Write-Host "Looking in " $foldername " for things to copy"
if(!(Test-Path $TargetPath))
{
try{
Copy-DatastoreItem -Item $foldername -Destination $localname -ErrorAction Stop
}catch{
switch -wildcard ($error[0].Exception.ToString().ToLower())
{
"*already exists*" {Write-Output "File Already Exists"}
default {
sendMail($error[0].Exception.ToString().ToLower())
}
}
}
try{
Copy-DatastoreItem -Item $localname -Destination $TargetPath -ErrorAction Stop
}catch{
switch -wildcard ($error[0].Exception.ToString().ToLower())
{
"*already exists*" {Write-Output "File Already Exists"}
default {
sendMail($error[0].Exception.ToString().ToLower())
}
}
}
Remove-Item $localname -recurse
}
Recusive2VcenterDSCopy -ItemPath $foldername -TargetPath $targetfoldername
}else{
$foldername=$ItemPath+"\"+$dsItem.Name
$targetfoldername=$TargetPath+"\"+$dsItem.Name
$localname="C:\Scripts\appvolsync\"+$dsItem.Name
$remoteFile=$TargetPath+"\"+$dsItem.Name
if(!(Test-Path $remoteFile))
{
Write-Host $remoteFile "Does not Exist"
try{
Copy-DatastoreItem -Item $foldername -Destination C:\Scripts\appvolsync\ -ErrorAction Stop
}catch{
switch -wildcard ($error[0].Exception.ToString().ToLower())
{
"*already exists*" {Write-Output "File Already Exists"}
default {
sendMail($error[0].Exception.ToString().ToLower())
}
}
}
try{
Copy-DatastoreItem -Item $localname -Destination $TargetPath -ErrorAction Stop
}catch{
switch -wildcard ($error[0].Exception.ToString().ToLower())
{
"*already exists*" {Write-Output "File Already Exists"}
default {
sendMail($error[0].Exception.ToString().ToLower())
}
}
}
Remove-Item $localname -recurse
}
}
}
}
$productionVCenter=Connect-VIServer -Server <production vcenter would be here>
$recoveryVCenter=Connect-VIServer -Server <recovery vcenter would be here>
Import-Csv "C:\scripts\appvolsync\appvolsynccfg.csv" -UseCulture | %{
$productionDatastore=Get-Datastore -Server $productionVCenter -Name $_."PDC"
$recoveryDatastore=Get-Datastore -Server $recoverVCenter -Name $_."SDC"
if(!(Test-Path pds:\))
{
New-PSDrive -Location $productionDatastore -Name pds -PSProvider VimDatastore -Root "\"
}
if(!(Test-Path rds:\))
{
New-PSDrive -Location $recoveryDatastore -Name rds -PSProvider VimDatastore -Root "\"
}
Recusive2VcenterDSCopy -ItemPath "pds:\cloudvolumes" -TargetPath "rds:\cloudvolumes"
remove-psdrive -name pds
remove-psdrive -name rds
}
sendMail("Completed Appvolumes Sync")
Disconnect-VIServer -Server $productionVCenter
Disconnect-VIServer -Server $recoveryVCenter
I was looking at something similar, but afaik currently the cross-SSO is only working for cloning and vMotion (see KB2106952).
I was hoping the VcenterVStorageObjectManager might have offered some possibilities, but apparently that one doesn't cross-SSO.
In the end I fell back to using SCP (and yes, that requires SSH on both ESXi nodes to be enabled).
With the Posh-SSH module that is quite straightforward.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was looking at something similar, but afaik currently the cross-SSO is only working for cloning and vMotion (see KB2106952).
I was hoping the VcenterVStorageObjectManager might have offered some possibilities, but apparently that one doesn't cross-SSO.
In the end I fell back to using SCP (and yes, that requires SSH on both ESXi nodes to be enabled).
With the Posh-SSH module that is quite straightforward.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD , I've seen you mention the scp route before, but I know I'll never get that past our security team. Here is hoping it gets added in the future, this way works but its at least 3 times as long and excess io I don't really need in the environment. The product has a feature that uses a shared nfs datastore between the environments, which I hope to convince our team in the future to use, but I can't even get that approved yet.