Clone the virtual machine to the local data store

Hi all

I'm looking to automate a task daily (or almost) of my friends with a small script with powercli.

I'm trying to "backup" or to clone a virtual machine, I work in a storage of one of our servers.

The servers are managed by a 5.1 vCenter and the machine is on a shared storage.

From time to time, I clean, stop the machine, remove all snapshots and clone the virtual machine to one of the local server as a backup storage. So I put together a small script which almost works. It works as long as the target data store is a shared storage, but not with a local storage.

I get always an error that claims it can not access the local data store and is not a permissions problem...

Given that I can accomplish this via the customer without problem I thought it is possible via powercli too, or I'm wrong?

My Script up to now:

# Variables
$VC = "vc.domain.com" #vCenter Server
$User = "domain\user" #User
$Pass = 'test123' #User PW
$VMName = 'scripttest' #VM
$BackupSuffix = "backup" #Suffix to add the name of VM to mark this as a backup
$VmHost = "esx2.domain.com".
$Datastore = 'ESX2-LocalData' #Datastore
$BackupFolder = 'Backup' #Folder the VM gets classified


# Register cmdlets to VMware

If (-not (Get-PSSnapin VMware.VimAutomation.Core - ErrorAction SilentlyContinue)) {}

Add-PSSnapin VMware.VimAutomation.Core

}


# Connect to the server

SE connect-ViServer $VC - user $User-password $Pass


# Remove the old clone

$OldBackups = get - VM | WHERE {$_.} {Name: corresponds to '$VMName - $BackupSuffix'}

If ($OldBackups - don't "")

{

If ($OldBackups.Count - gt 1)

{

Write-Host "better check! "Found several results:

Foreach ($VM to $OldBackups)

{

Write-Host $VM. Name

}

}

on the other

{

Remove-VM - VM $OldBackups - DeleteFromDisk-confirm: $false

}

}


# Clone VM

$VMInfo = get - VM $VMName | Get-View

$CloneSpec = new-Object Vmware.Vim.VirtualMachineCloneSpec

$CloneSpec.Snapshot = $VMInfo.Snapshot.CurrentSnaphshot

$CloneSpec.Location = new-Object Vmware.Vim.VirtualMachineRelocateSpec

$CloneSpec.Location.Datastore = (get-Datastore-name $Datastore |) Get - View). MoRef

$CloneSpec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]: sparse

$CloneFolder = $VMInfo.Parent

$CloneName = "$VMName - $BackupSuffix".

$TaskCloneID = $VMInfo.CloneVM_Task ($CloneFolder, $CloneName, $CloneSpec)


# Check if the task is completed


$Check = $false

While ($Check - eq $false)

{

$Tasks = get-job | Select State, id | Where {$_.} State - eq "Running" - and $_. State - eq "pending"}

ForEach ($Task in $Tasks)

{

If ($Task.id - eq $TaskCloneID)

{$Check = $false}

on the other

{$Check = $true}

}

Start-Sleep 10

}

# Move clone to the backup folder

Move-VM - VM '$VMName - $BackupSuffix' - Destination $BackupFolder


# Disconnect

Disconnect-VIServer-confirm: $false

Can you show us the complete error message you get?

BTW, the clone step can be replaced by the New-VM cmdlet with the setting of the virtual machine.

Tags: VMware

Similar Questions

  • How can I move virtual machines from a local data store for a new iSCSI SAN?

    Hello guys,.

    Now that we have a new iSCSI SAN market how can I tranfer all the virtual machine to a local data store for a new SAN? Can I stop the VM in the host, and then copy the DataStore files with all the info on the new volume?

    Thank you

    Pesinet

    Alternatively, you can use VMware converter or cold Migration / Storage VMotion if you have the appropriate licenses.

    Duncan

    VMware communities user moderator | VCP | VCDX

    -

  • Clone a virtual machine to a Cluster data store

    Hello

    Really simple (hopefully), but I'm trying to write a workflow that includes the provision of a virtual computer to a cluster of data store. I'm a link to the workflow 'Clone the virtual machine, no customizations' that only accepts a store of input data.

    I hope that I am a bit stupid here and there is a simple answer?

    Thank you.

    There is no simple answer.  DRS clusters are actually a set of rules and not a real thing, you can deploy a VMDK.  I suggest to use Onyx to deploy a virtual computer to a DRS cluster and see what it generates.  If I remember correctly, it executes DRS rules to get a recommendation for where to put a VMDK fundamentally and then uses the exit in order to actually deploy the model.

    I opted to write just a simple workflow that finds the data store with the most of freespace that corresponds to a string - for example, if I have a DRS cluster named DSCluster_ugabuga, I have a lot of data stores named something like "ugabuga... ».  So you ask these storages of data and find the one which most freespace.

  • Expand the Local data store

    Hello

    I have an ESX 4.1 with only a data store local (RAID5) on virtual machines on a DELL Server

    I want to enlarge the data store, I don't have enough free space to create multiple virtual machines.

    To do:

    -Install a new hard drive (with vmware powered)

    -Add the new hardisk to Raid5 with DELL Open manage

    -wait finally extend raid 5

    -Power Off Vmware machines?  or continue started?

    -Develop with local Vshpere the data store vmware (what time must expand?)

    I want to know if I can do an extension with the new space unpartitioned on local existing datastore without losing my virtual machines? I have only the local data store with esxi when I develop the esxi continue to work?

    Can someone help me?

    Concerning

    Yes, it's quite OK.

    If this solved your problem, please mark it as answered.

    See you soon,.

    Adil Arif

  • Can I delete the local data store on esx 3.5?

    I have a client with vmware ESX 3.5 no esxi

    They have a local data store but it is formatted with a block size of 1 MB, so I can put only a 256 GB VM out there and I need to put a test VM with a larger size.

    I know that in ESXi 4 you can simply delete the local data store and create a new, but I'm not familiar with ESX 3.5, are there hidden files on the data store that the server uses?  If I search for the store there's nothing in there.

    Thank you

    Mike

    Hi Mike,.

    You can simply reformat your data store. Take a look at the following article:

    Of course, you must back up and delete any data you have on this data store before the format operation.

    Good luck!

    Concerning

    Franck

  • Cannot delete the local data store empty on ESXi 4

    Hi all

    Does anyone know how to kill the process that uses / block the process of removing the ESXi 4 data store?

    I have this provblem in VI Client when I was in the middle of the removal of the Local data store

    Remove datastore

    The resources ESXi02_VMFS vim.host.DatastoreSystem is in use.

    It's production live environment so is possible to kill the process without having to restart the ESXi 4 crowd?

    Thank you.

    Kind regards

    AWT

    OK so first try to connect with viclient to ESXi directly and see if you can remove the data store.

    The command you need to nod your head do buisness hours.

    Good luck!

    MCP, VCP

  • How to move a virtual machine to a different data store, preserving its ID

    I would like to move a virtual machine to a different data store.

    Because I use 3rd party software that identifies a virtual machine by its ID of VirtualCenter, I'd like to preserve the ID, and I also want to preserve the name of the virtual computer.

    If I clone the virtual machine, I lose the ID and name.

    I can clone a second time to restore the name, but the ID is always false.

    I know that I can use vmkfstools-i to copy the entire disk.

    Is it possible to copy the entire VM?

    I am currently on ESX 3.0.2/VC 2.0.2

    The operation that I describe is available in 3.5.x/VC ESX 2.5.x

    TIA,

    -Magister

    Don't use EVER of CP to copy a VM, VMDK move/copy should be used in conjunction with vmkfstools as best practice.

    OP,

    You can manually make a copy using the CLI interface or use the VI Client and browse the data store and to copy and paste in the appropriate data and as suggested Andre store, when you switch on for the first time, you should say 'keep' when asked if you want to update the virtual machine UUID.

    Another thing, you could do, is if you've enabled for vMotion, you can actually use Storage vMotion which will migrate directly from your virtual machine to a different data store, it's less effort on your side and you can count on Andrew Kutz sVMotion plugin: http://sourceforge.net/projects/vip-svmotion/

    =========================================================================

    William Lam

    VMware vExpert 2009

    Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

    repository scripts vGhetto

    VMware Code Central - Scripts/code samples for developers and administrators

    http://Twitter.com/lamw

    If you find this information useful, please give points to "correct" or "useful".

  • List not updated virtual machines after the migration of the virtual machine to a different data store

    My vSphere infrastructure 5 uses several data stores.

    Two data warehouses are associated with NFS on different NAS shares.

    I migrate VM to a data to another store.

    The navigation data store, I see that the files are moved from the old data store to the new and that no file belonging to the migrated VM still does exist on the old data store.

    If I look at the list of VMs on the old data store, I still see the old VM.

    I see it in the list of the virtual machine on the new data store as well.

    I checked that no .iso no pagefile is in the old data store.

    How can I update the list of the virtual machine on the old data store?

    Above all, how can I safely delete the old data store by ensuring that the virtual machine works very well on the new data store and I don't lose anything?

    Concerning

    Marius

    This use of data store 'Phantom' is usually observed, if the current configuration of the virtual computer points to the 'old' data store (diskette, CD-ROM) or the virtual machine contains snapshots where - at the time where tone have been created - the VM has had these references. Once the snapshots are deleted from data store 'ghost' will go away from summary of the virtual machine.

    André

  • Extremely high latency during the migration of the local data store to data store shared.

    Hi guys I hope you help me. Sorry for my English btw, I'm not native.

    Let's start!

    I have:

    1 vCenter
    1 host
    1 Distributed Switch (with a pg for managing network/IPstorage the esxi)
    1 standard switch (empty)
    1 FreeNAS to provide iSCSI LUNS
    1 Microsoft to provide iSCSI LUNS

    When I try to migrate virtual machines between the warehouses of shared data or data shared at local store, all right. The problem has become when I try to migrate virtual machines from the local to the shared data store. All data stores down (all paths down) and back up and I get this error:

    "Error caused by the /vmfs/volumes/volumenID/VMDirectory/Disk.vmdk file.


    When I try to migrate virtual machines from the local to the FreeNAS iSCSI data store it fails immediately.
    When I do the same local Microsoft iSCSI datastore that it takes a time loooooong to migrate the virtual computer, give it to me even all the paths downwards and uplinks down error but not lacking in migration.

    I'll give you some screenshots to see the errors.

    Thank you very much!

    EDIT: I have extremely high latency notice when I try to migrate from the premises of warehouses of shared data. average 2000ms with peaks of 50,000 (see my response below for more information)

    Finally, I found the solution! The problem is that I have been using E1000E vmnic instead of vmxnet3. I have configured an adapter vmxnet3 and boom! 20 ms in all migration!

    Thank you to all for help, especially Nick_Andreev !

  • Deployment uses the local data store

    The deployment of VIO works without problem, but one of the virtual machines (VIO-DB-0) is now in a local data store. I never chose this data store in the installation process.

    Is it possible to manually move the virtual machine? Is it possible to define the data store used for the management of virtual machines somewhere?

    Concerning

    Daniel

    Hi Daniel,.

    Take a look at VMware integrated OpenStack 1.0 Release Notes:

    • Installer gives priority to local storage by default
      When you set up the data for the database stores three virtual machines, VMware OpenStack Setup integrated automatically gives priority to a local storage to improve IO performance. For resilience, users might prefer a shared storage, but the installer does not clear how to change this setting.
    • Workaround: Before completing the installation process, the installer of VMware OpenStack integrated allows you to examine and change the configuration. You can use this opportunity to change the configuration of the data to the database store three virtual machines.

    If you have already installed VIO, AFAIR you should be able to manually move between data warehouses as long as you do not change VM itself.

    Note that there is rule anti-affinite, so you may not be able to move that VM in the same data store when no other VIO - DB resides.

    Another note is that if you turn off VIO-DB-0, mysql service will not appear automatically. you have to turn on manually by running "service mysql start" on the node itself, or run 'vioconfig start' of the SGD server.

    Best regards

    Karol

  • Adding/viewing ESX hosts the local data store in vCenter

    Hey all,.

    I am pleased to join these forms and hope I have don't get dessu down for not having a cert VM (I train hard knowledge where and how get it)

    I have recently graduated from networking and am on the fast track in my new career. Now things are as clear as possible so I will try to fill as much

    ESXi 1 - Dell G6, running, 1065491 5.1.0

    Storage adapter - Smart Array P410i

    vmhba0

    Details - Serial Attached SCSI disk HP, ID (naa. #...), name of Runtime: vmhba1:c0:T0:L0, mounted the Non - SSD, block adapter, 1 TB)

    ESXi 2 - Dell G7 5.1.0 running, 1065491

    Storage adapter - Smart Array P410i

    Details-HP Serial Attached SCSI Disk, ID (naa. #...), name of Runtime: vmhba1:c0:T0:L1, mounted the Non - SSD, block adapter, 1 TB)

    vCenter - Win Server 2008 r2 (working on the features of powershell to work with packages from CodePLex)

    ESXi hosts in a single datacenter, with one single Cluster... in this cluster is a SAN that the two hosts can access without problem

    When I click on Cluster 1-> summary-> Storage (local storage shows ESXi 1 and SAN storage) NO ESXi 2 of local storage.

    When I click on ESXi 1 host in vCenter and then click on summary or Configuration (Storage)... it will show the SAN and hosts local storage

    When I click on ESXi 2 host in vCenter and then click summary or Configuration (Storage)... it will show the SAN and NOT hosts local storage

    How can question I view and manage local storage of 2 ESX via vCenter?

    At the moment I have to hand, log in to ESX 2 via vSphere thickclient and see its local data store.

    I was talkin to some people on #vmware in IRC, but can't seem to understand why... is something mmiss configured? I thought that this would have been a no-brainer... I tried to 'find new warehouses of data' on the ESX 2 in vCenter, no dice.

    Help

    Welcome to the community - I would try to remove the host to vCenter and see if you can see the local storage.

  • Cannot create the local data store more Go 558,75

    See attachment.

    New installation of ESXi 4.1.0 try adding a local data store.  Local volume is a to 4.55 RAID 5, fully initialized.

    Add storage

    Choose the device, etc.  Choose the size of 8MB block and "ability to mazimize.  Summary On screen looks like its going to do what I ask... I cliquerai finish.

    Produces final is 558,75 Go.  Any ideas?

    ESX(I) supports no more than a little less than 2 TB LUN. Divide your table into smaller LUNs

  • Increase in the size of block of the local data store

    I tried from Googling and it involves a lot of things from the command line and seems to be different ways of doing.

    They say that I need to format the drive again and specify a block size.  But isn't ESXi installed on the same partition? If I reformat it, it won't get rid of the ESXi software?

    Where can I get easy step by step instructions on how to do this?

    If you have no data, go to Configuration / Storage and remove the existing data store.

    Then choose Add datastore.

    André

  • Size of the virtual machines on the local data store

    What is the best way to determne the (total) disk space using a virtual machine? We have several virtual machines on local data warehouses and would like to estimate roughly how much disk space to the total number of virtual machines use to caculate how much storage SAN, they will consume. Is there an 'easy' way to socket this information?

    The most accurate way would be to calculate the total space used by the virtual machine files in the data store.

    Connect to the service console

    Navigate to the vmfs volume

    Navigate to the vm folder

    -h.

    This will give you files for this particular virtual machine related to the amount of disk space used by all the vm

    Méhul

  • Migration of virtual machines store data Local to the Local data store

    I spend a few VMs storage local servers ESX 3.5 to local storage on another. The customer, I work with a Vcenter but doesn't have a Vmotion.

    What would be the best way to carry out the removal.

    Cold migration?

    Import to the new ESX Server via converter?

    I tried to do an import with the virtual machine is turned off and after 30 minutes, the progress is only 5%. This server only took 25 minutes for P2V, cold import of VM VI3 to VI3 VM takes longer to P2V? It is a LAN Gigabit environment all.

    When I tried to make the trip through the migrate, progress suspended at 25% and never finished.

    Migration cold will work fine.  Stop the click Guest, just choose migrate.

Maybe you are looking for