
[en-US]
Recentemente me deparei com um cenário interessante. O cliente criou e “voltou” diversos snapshots de um determinada VM e precisava coletar um arquivo que só estava disponível em um desses snapshots.
O problema é que não era possível voltar a VM para o estado no qual os arquivos estariam disponíveis. Ela já estava em um cenário produtivo e gerar uma indisponibilidade estava fora de questão. Desta forma, como seria possível acessar o disco de snapshot sem que fosse gerada uma indisponibilidade?
Bom, existem diversas formas de se acessar um disco VMDK, mas na maioria delas o arquivo do disco não pode estar em um estado locked, ou seja, o arquivo não pode estar sendo usado por uma VM que estava ligada. Quando o arquivo VMDK está neste estado, não é possível acessá-lo ou copiá-lo para um outro diretório ou device. Sendo assim, baseando-se em todas essas limitações, a melhor maneira de se acessar o disco seria efetuando um clone dele. O clone é o único processo de cópia que funcionar com o arquivo VMDK em um estado locked. O detalhe aqui, é que pela interface gráfica não existe nenhum botão que permita clonar um disco específico (no vCenter. O VMware Workstation permite criar VMs a partir de snaphosts), e clonar a VM inteira irá consolidar todos os discos, o que não atenderia nossa demanda. Então, como resolver esse dilema? Na verdade é bem simples. Usando PowerCLI:
Digamos que temos a VM Sistema01 que contém os snapshots atualizacao01, atualizacao02 e atualizacao03 e precisamos obter um arquivo que está no snapshot atualizacao02. Sendo assim, precisamos clonar esse snapshot. Essas são as linhas de código que deveríamos usar para realizar tal procedimento:
New-VM -Name $VMCloneName -VM $VMSourceName -Datastore $DatastoreName -VMHost $VMHost -LinkedClone -ReferenceSnapshot $SnapshotName
Onde:
- $VMCloneName = Nome da nova VM que será criada a partir do snaphost;
- $VMSourceName = VM que contém os snapshots que serão usados como referência;
- $DatastoreName = Datastore de destino no qual a nova VM será alocada;
- $VMHost = ESXi Host no qual a nova VM será alocada;
- $SnapshotName = Nome do snapshot a partir do qual a nova VM será criada.
No nosso cenário, para criar a VM a partir do snapshot atualiazcao02, o código ficaria desta forma:
$VMCloneName = “clonefromsnapshot”
$VMSourceName = “Sistema01”
$DatastoreName = “DATASTORE01”
$VMHost = “esxi01.local.lab”
$SnapshotName = “atualizacao02”
New-VM -Name $VMCloneName -VM $VMSourceName -Datastore $DatastoreName -VMHost $VMHost -LinkedClone -ReferenceSnapshot $SnapshotName
A execução do código acima resultaria na criação da VM clonefromsnapshot no datastore DATASTORE01 e no Host ESXi esxi01.local.lab a partir do snapshot atualizacao02. Uma vez que a tarefa tenha sido concluída, é possível ligar a VM criada e acessar seus arquivos, ou ainda copiar o VMDK desejado e mapeá-lo em uma nova VM ou acessá-lo usando ferramentas como o VMware Virtual Disk Development Kit (VDDK).
Bom, é isso pessoal. Espero ter conseguido ajudá-los de alguma forma. Caso tenham alguma dúvida, não deixem de escrever nos comentários.
Recently I had a very interesting scenario. A customer made and return several snapshots of a specific Virtual Machine, and needed to collect some files that were present in one of these snapshots.
The problem is that was not possible rollback the VM to the state in which the files would be available. The VM was already in a production environment and unavailability was out of the question. Thus, how would be possible to access snapshot disk without have an interruption of services?
Well, there are several ways to access a VMDK disk, but in most of them the disk file can not be in a locked state, that is, the VMDK file can not be used for any VM powered on. When the VMDK file is in a locked state, it is not possible access or copy it to a new directory or device. Therefore, thinking in all of this limitations, the best way to access this disk would be creating a clone of it. The clone is the only process that works to a VMDK file in locked state. The detail here is that there is no way to do a clone of a specific disk or snapshot in the GUI (vCenter GUI. In VMware Workstation there is a way to create VMs from a snapshot), and clone the entire VM would consolidate all snapshosts, what would not meet our demand. So, how to solve this problem? In fact, it is very simple. Using PowerCLI:
Let’s say that we have VM called System01 that contains the snapshots update01, update02 and update03 and, we need to get one file that is present in snapshot update02. So, we need to clone this is snapshot. There are the code lines that could be used to do this procedure:
New-VM -Name $VMCloneName -VM $VMSourceName -Datastore $DatastoreName -VMHost $VMHost -LinkedClone -ReferenceSnapshot $SnapshotName
Onde:
- $VMCloneName = Name of the new VM that will be created from the snapshot;
- $VMSourceName = VM that contain the snapshot that will be used as reference;
- $DatastoreName = Destiny datastore where the new VM will be allocated;
- $VMHost = ESXi Host where the new VM will be allocated;
- $SnapshotName = Name of the snapshot from which VM will be cloned;
In our scenario, to create the VM from the snapshot update02, the code woule be like this:
$VMCloneName = “clonefromsnapshot”
$VMSourceName = “System01”
$DatastoreName = “DATASTORE01”
$VMHost = “esxi01.local.lab”
$SnapshotName = “update02”
New-VM -Name $VMCloneName -VM $VMSourceName -Datastore $DatastoreName -VMHost $VMHost -LinkedClone -ReferenceSnapshot $SnapshotName
The execution of the code above would result in the creation of the VM clonefromsnapshot in the datastore DATASTORE01 and in the ESXi host esxi01.local.lab from the snapshot update02. Once the tasks has been completed, it is possible power on the VM created and access its files, or copy the desired VMDK file, map it in other VM or access it using tools like VMware Virtual Disk Development Kit (VDDK).
Well, that is all, guys. I really hope I have been able to help you in some way. Please, in case of doubts, be sure to write in the comments.