开发者

VM Clone to the Subdirectory of a Datastore

I have a Datastore in vCenter that I'm trying to clone to using a PowerCLI script I run weekly. I can clone virtual machines to it, but I have absolutely no control over the directory structure. It's throwing every virtual machine in a folder named after the virtual machine, on the root of the datastore.

My Ideal directory structure is with the Root only being utilized for active virtual machines. a "BACKUPS" folder exists. Inside that folders are created weekly to store the weekly clones. Example "20111004" for today. Inside that folders exist for each virtual machine.

$vm = <name of the virtual machine obtained programmatically>
$date = Get-Date -Format "YYYYMMDD"
$h = <ESXi host where the VM is located, obtained programatically>
$dsName = "DATASTORE1" #<Name of the datastore I'm targeting>
$dirPath = "BACKUPS/" + $date + "/" + $vm

New-VM -Name $vm-$date -VM $vm -VMHost -$h -Datstore $dsName -Location $dirPath

Example of a "full" path

[DATASTORE1] BACKUPS/20111004/VIRTUALMACHINE

This is the only piece of the script that doesn't work. When the command is given this way in PowerShell it completely ignores the -Location parameter and throws the clone on the root of the datastore. I haven't found any documentation (that I understand) about how its supposed to b开发者_如何转开发e formatted yet. Something to do with a VIContainer ??

Script Source I'm customizing:

http://www.mbnbusiness.co.uk/blog/2010/08/updated-powercli-vmware-vm-backup-script-v2-0/


The -Location defines the vCenter folder into which a VM is placed, not a folder within a datastore within which to place the VMs files.

As far as I am aware, a VMs files must be placed on the root of the datastore.

I considered trying to do a similar thing when I first created the script as it made the archiving of old backups easier, but I could not find a solution at the time.

Sorry I can’t help more…


I sounds like you're trying to do backups and I would highly recommend you look at an actual backup product like VMware's Data Recovery or Veeam's Backup utility.

Like @Mike said, VM files work at the root of the Datastore. You could create multiple datastores and cycle through them for backups but this could be very pricey if you're using high performance disks.


I tried using $date = Get-Date -Format "YYYYMMDD" but ended up with the output being YYY01DD.

Changed to $date = Get-Date -uformat "%d%m%Y , I now get 01012012

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜