Good evening,
we do run a test lab with some bigip appliances. As we play around with them and usually mess them up i wanted to create a clone to have a full backup of a clean appliance.
i figured out when i copy the bios.uuid i will not loose the activated license and so i do not need to bother the vendor again and again.
I am stuck in my scheduled task with the replacement. The tasks run shutdown the vm and take the clone.
I have to run these actions in jobs don't ask me why. I could figure out why the "pure" commands do not work.
So here is the piece where i am stuck... And i would love if someone could enlighten me to get this to run.
I tagged the machines so the bios.uuid will not get replaced on other machines. Having the vendor details of the vm would be much cooler and i might open another post about this.
So i get the uuid from the master vm
# Get BIOS UUID
$uuid = Get-VM $vmname | %{(Get-View $_.Id).config.uuid}
And geht the Tag of the vm
# Get Tag of Virtual Machine (if assigned)
$tag = Get-VM $vmname | Get-TagAssignment | select Tag
$vmname is the master
$firstbackupname is the name of the clone
And here is the code which should replace the uuid on the vm ($firstbackupname)
if ($tag -match "F5") {
LogWrite ""
LogWrite "Task Backup - F5 Tag assigned. Changing UUID"
Start-Job -ScriptBlock {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.uuid = $uuid
$firstbackupname.Extensiondata.ReconfigVM_Task($spec)
}
Get-Job | Wait-Job
LogWrite "-OK-----------------> Changed UUID to $uuid"
}
The scenario does shutdon the vm, wait for shutdown then take a clone and now it should copy the master uuid to the clone. Right after the vm gets a power on.
I would be very happy if you coudl help me out here.
thank you very much for any tip and help.
best wishes armin
Do you remove the 'master' completely before trying to assign the UUID to the clone?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
no the master will run until he is so misconfigured that we need to restore it to a clean state.
We do keep it and a clone (fresh installed with base config) as a backup.
And to keep the license activated the vm needs to have the same uuid.
thanks!
I'm not sure that vCenter will allow VMs with the same UUID to co-exist
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
the backup stays offline and disconnected. If the master fails it will get deleted.
And the clone will get the master.
They will never run or being online at the same time.
See it like a save copy of the master.
thanks
But they are both present in the vCenter database
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Correct Luc.
I can replace the uuid with the command manually.
But would like to script it with the clone automation
Manually works:
#
# Get BIOS UUID
$uuid = Get-VM $vmname | %{(Get-View $_.Id).config.uuid}
#
# replace UUID on backup
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.uuid = $uuid
$firstbackupname.Extensiondata.ReconfigVM_Task($spec)
But in the scheduled job clone script it does fail.
if (Get-VM $vmname | Get-TagAssignment |where{$_.Tag -like “F5*”}) {
Get-VM $firstbackupname
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.uuid = $uuid
$firstbackupname.Extensiondata.ReconfigVM_Task($spec)
}
And i do not understand why it fails and runs manually in ISE editior but not with powershell in a scheduled task.
had this with other actions like clone or delete a vm too. So here i used jobs to run in. Maybe because it is a scheduled task.
Is there any error message when it fails?
You could check the vpxd log, eventually setting the log level temporarily to 'verbose', for additional information.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did some further testing (in vSphere 7).
I was able to change the UUID on the cloned VM, irrespective if the source VM was powered on or not.
The conclusion would be that the issue is in your scheduled job.
How did you create the scheduled job?
Under which account does it run?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
thanks for your help.
The account is a domain account which has local admin rights on the vcenter appliance. (All rights assigned)
About the job. This runs on a windows server and i use scheduled task.
trigger task
Runs every hour, collect data from csv and triggers the action script.
# Script will check if time and backup matches on CSV
# Then it does trigger all actions below
#
$csv | ForEach-Object {
if (($_.backup -match “yes”) -and ($hour -eq $_.time) -and ($_.days -match $today))
{
LogWrite ““
LogWrite “Time $hour o’clock Basel Time”
LogWrite “Session collection details for each machine”
LogWrite “$_”
$job = Start-Job -Name $_.vmname -FilePath “c:\Scripts\vm_backups\actions\vm_backup_action.ps1” -ArgumentList $_.vmname,$_.vmbackupname,$_.shutdown,$_.retention_local,$_.retention_nas | Out-Null
Start-Job -ScriptBlock $job
Get-Job | Wait-Job
}
}
Action script uses data from csv (param) and connects to the vcenter via encrypted credentials.
Strange is that i have to put every clone task into a job.
# Create backup job
$job = New-VM -Name $secondbackupname -VM $firstbackupname -Datastore $freespace2 -Location $backupfolder -VMHost $freespace2esx -notes $date
Start-Job -ScriptBlock $job
Get-Job | Wait-Job
Start-Sleep -Seconds 10
#
As soon i try to run the command without $job it does fail.
I did not found out why it fails but to complete i did then use jobs to run the action.
So maybe i need to run the change UUID task as a job as well.
Need to try.
Not sure how i should pack these commands into a job.
THe others are in one row. This looks like to need more.
Start-Job -ScriptBlock {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.uuid = $uuid
$firstbackupname.Extensiondata.ReconfigVM_Task($spec)
}
Idea:
$job = {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.uuid = $uuid
$firstbackupname.Extensiondata.ReconfigVM_Task($spec)
}
Start-Job -ScriptBlock $job
Get-Job | Wait-Job
Maybe this will succeed...
What do you think?
How does it fail when you don't run it as a job?
Any error messages?
Perhaps try adding a transcript (Start-Transcript/Stop-Transcript) and verbose mode ($VerbosePreference) to get more details.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That will work (with the Start-Job).
Just define a code block (curly braces) with multiple lines.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Luc,
i will try. Keep fingers crossed.
Luc, thank you very much for your help!
This thing drives me mad....
Since this morning when i try to run the script from ISE editor or powercli i receive an error...
Variable of $uuid and $vmname is correct and gets listed when i call them.
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.uuid = $uuid
$vmname.Extensiondata.ReconfigVM_Task($spec)
You cannot call a method on a null-valued expression.
At line:3 char:1
+ $vmname.Extensiondata.ReconfigVM_Task($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Any clue on what seems to be wrong?
I compared the commands and all looks well....
frustrating...
Thanks!
I'm not sure what you have in $vmName.
Perhaps show the complete code to let me get an idea
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference