📜 ⬆️ ⬇️

Backups of Hyper-V virtual machines and regular computers

I want to share with you the experience that took me a lot of time - about backups of virtual machines and ordinary computers. How to make cheap and beautiful.

Perhaps I'll start with the fact that if you want backups on VMWare, then get ready to pay. Free VMWare is free as long as it’s not about migrations, backups, and so on. At this place you can start an endless holivar, but without my participation. My narrations will be only about Hyper-V on Windows Server 2012R2. Although part of the article can be applied to VMWare, there are likely to be pitfalls.

We can back up to Hyper-V for free, or rather, with the Windows tools we already paid for by purchasing Windows Server licenses. For the convenience of working with our backups (we also paid for it), we will use WDS and deduplication (maybe group policies).

1. Backup from inside virtual machines


1.1. Backup of today


As far as we know, any Windows can backup. Moreover, any Windows backup settings through the interface are reduced, ultimately, to the background use of the wbadmin utility. And what, in fact, can wbadmin? And she knows how to do a backup image with the system partition, and backup individual folders. In this part of the article, we are only interested in the backup image (of the system partition). The rest is specific data of virtual machines and it is necessary to back up separately. Hence the conclusion: Do not store any valuable information and databases, individual applications on the system partition of virtual machines (and on ordinary computers too). MS SQL Server / MS Exchange / "Application Server 1C" and another set only on non-system partitions or on separate disks.
')
So, what does it take for the backup to work? And only one team is needed:

wbadmin.exe start backup -backupTarget:\\\ -allCritical -quiet 

Actually, for this command special rights are needed, but about them later. Now it is important to understand one thing. This command does not just backup. It makes an incremental backup. Moreover, for server and desktop (client) Windows backups are formed different. And the difference lies in the fact that for server OS we will get pictures of each backup, but for the desktop OS, only the last one will remain. Ask, what is this incremental backup? And “incremental” it remains, because we are not backing up the whole image, but only the changed part since the last backup (and therefore less traffic and a backup is created faster).

Those who are faced with a similar situation will notice that the backup will always be "incremental" (full). Since backup occurs in our case on a network drive. That is, for server-side Windows, the snapshots also remain the last

Later, I discovered that there is no difference in the work of wbadmin on the server and client OS. Is that the difference is in the interface. wbadmin makes an incremental backup (except for the first backup) if the hard disk is specified in the -backupTarget key (the command uses the default -vssSopy key). Or it makes a full backup if you add the -vssFull switch.

1.2. Backup with the history of previous shots


At the moment, we made a backup of images of virtual machines. But this is a backup of only today's pictures. Tomorrow it will be completely different ... But what will happen if you back up backups? Yes, and still truly incremental. So do.

 wbadmin.exe start backup -backupTarget:e: -allCritical -include:d: -quiet #  D -   ,   E -    

But this was not enough for me and I did this:

 ( echo select vdisk file="\\2\2\2.vhdx" echo attach vdisk ) | diskpart 

The script connects the virtual disk from the network. After backup, a similar script disables the disk. The OS remembers that the drive has an E letter. But God forbid to slip someone else's drive with the same letter E, the backup will work out to the fullest (not incrementally and onto someone else's drive). Keep this in mind and use the letter closer to the end of the alphabet (X, Y, Z) ...

I note right away that if today's backup will be made in parallel with the backup with history, we will end up with a backup that cannot be raised.

To get the backup of the previous days, you can use the interface (GUI) of the server on which backups with history are made. Moreover, all the launches of the wbadmin command in the Windows console know and remember. Recovery service will enable you to select the desired archive in backups with history.

2. Backup of vhdx files of virtual machines


It is made easily and naturally:

 wbadmin start backup -backupTarget:$BackupPath -hyperv:$VMList -Quiet 

But with some features. This command should be executed in PowerShell and with a preliminary receipt of the list of virtual machines into a variable. For a detailed example, go to Google.

Backup of virtual machines in Windows Server 2012 R2 is performed using Hyper-V snapshots. Also note that there is a suspension of the work of virtual machines if there is a Linux kernel on them or there are no Hyper-V drivers. I personally refused to back up virtual machines in this way. The reason is that on Windows Server 2012 (not R2), it was necessary to stop the virtual machines before backup. And now, on Windows Server 2012 R2, the suspension of Linux does not suit me when there is a first good way to backup. (there is a remark in the comments to this article). After the next update in Windows Server 2012 R2, backup of any virtual machines passes without interruption. Linux can also be backed up from the inside using Dump (CentOS, Ubuntu), but this is a separate topic with puppet and other software in my case.

3. Restoring backup and WDS


And now, in my opinion, the most useful part of this article about backups.

WDS is Windows Deployment Services (Windows Deployment Services) and part of the functionality of Windows Server 2012R2. Previously, this service was called RIS, but I did not come across it. In general, the essence of WDS is simple. They were registered in DHCP (automatically for DHCP Windows Server) as separate parameters and then downloaded to the computer via the network (such as setting the computer's BIOS to boot via the network) via TFTP WDS loader. Next, the WDS loader allows you to choose from the Windows “boot loader” images available on it. Boot loaders are different - this is the images of the installer loaders, and PE, and RE images. The installer bootloader still needs the Windows images themselves in the WDS, but this is in case you need to install Windows over the network. We are interested in RE images that allow you to pick up the car from the backup.

How and what works in the WDS will not explain in detail. But here are the important notes:

  1. If your RE bootloader loads on a Hyper-V virtual machine over the network, but the keyboard does not work in it. Congratulations, your RE image for WinXP or older and does not know about the existence of Hyper-V drivers.
  2. If your system starts restoring a backup, it stops. Delete all partitions on the hard disk (on which the backup is restored) and try again. Just do not forget that a backup can be broken and after deleting all partitions on hard you can have nothing left from the old information.
  3. If you backup UEFI, and you want to restore to a computer without UEFI, then you should not waste time. Most likely to deploy the backup will not work.
  4. A backup with UEFI boot and GPT partitions can be restored to machines with a different processor / motherboard, but it is unlikely to be able to deploy with MBR format partitions and with loading a regular BIOS on another machine. Well, I definitely did not succeed.
  5. If you try to deploy a backup to a disk with a smaller volume, then this will not work. Even if the disk in the backup was almost empty. In this case, recovery to a virtual machine with a dynamic disk helps. Further reduction of this disk and creation of a new backup. But this is possible only with the UEFI bootloader in the backup (why, read the previous paragraph).
  6. It is necessary to disable extra disks before restoring a backup in order not to overwrite the information on them.

4. Features of deduplication


You can deduplicate running virtual machines. You can deduplicate backups of today and you can deduplicate backups with history. All this gives a big positive plus to the amount of hard drives (both for HDD and SSD). But do not forget about some things:

  1. If deduplication works with disks with a volume of more than 1 TB, then the deduplication optimizer will use a lot of memory.
  2. If deduplication works with compressed data, but with a compressed volume of more than 10 TB, the duration of the deduplication optimizer will be too long. This can happen if you simply copy the data daily on a deduplitsirovanny disk in different folders.
  3. Backups on the HDD can be stored and even necessary, but working virtual machines should not be stored on the HDD in an amount greater than 5-10. By deduplication this is the only way that the deduplication of such working virtual machines will reduce the HDD performance to zero.

5. Group policies


Here you can implement the installation of the backup script using GPO for a long time and in different ways. But I would like to draw attention to the important points:

  1. Backup is carried out only on behalf of a separate user account.
  2. Do not store scripts with passwords in group policies.
  3. Run a script with special rights to read all the system information.

Well, in fact, the conclusion : Backup with the help of wbadmin tools is possible, fully implementable and most importantly viable. But only if you have time and a lot of patience for all sorts of little things. For example, the article does not say how to monitor successfully created backups. I managed to do monitoring at Zabbix, but you can write a couple more articles about this ... I hope the article will be useful for you and save you a lot of precious time.

Source: https://habr.com/ru/post/267307/


All Articles