Backup Script Idea, will it work?

Discussions related to using VirtualBox on Linux hosts.
Post Reply
JDaus
Posts: 3
Joined: 24. Oct 2021, 10:51

Backup Script Idea, will it work?

Post by JDaus »

Hi All,

I have read a lot about virtualbox backups and every single one of them says that you need to pause or shutdown the VM in order to backup.

I come from a long history of VMs, using virtualbox for years (but not in last 5-10 years or so), vmware, xenserver and more, but these were always sidelines for me, i learnt them because i needed to run software on them.

anyway, to my question, if i created a script that did the following, would the backups prove consistent?
  1. Get list of VMs
    Check status of VM
    If not running, get list of VDI's and snapshots, backup config, VDI's and snapshots (could also check backup files hash compared to currect or similar)
    If Running, Check if VM has live-backup config (not sure how to do this, maybe a file in the VM directory with the config file or something), if live backup:
    • backup config
      get a list of VDI and snapshot file locations into memory (for later backup)
      create new "backup" snapshot (so this is the only file being updated)
      copy VDI's collected from previous list to backup location
      once copy complete remove "backup" snaphost
    If no "live-backup"
    • backup config
      get a list of VDI and snapshot file locations into memory (for later backup)
      Pause the VM
      create new "backup" snapshot (so this is the only file being updated)
      Resume the VM
      copy VDI's collected from previous list to backup location, plus the new ".sav" file
      once copy complete remove "backup" snaphost
from my experience with other VM solutions (vmware) backups (and my limited knowledge of VBOX), this should work and provide consistent backups, granted that any software running on the "live-backup" VMs needs to be capable of restart on power failure, otherwise you would still need to pause the machine for those VMs that require this ...

I am looking for constructive feedback as to why this will or not work ... not just "it wont work" ... tell me why ... whats not going to work with it, how can i work around that?

I want to be able to backup VMs like firewalls that really need to remain running 24/7, but backups would make faster restore sooooo much easier ... things like windows DB servers would still need to be paused to allow allow memory to be saved.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Backup Script Idea, will it work?

Post by scottgus1 »

I would recommend to not use snapshots, even post-backup-deleted snapshots, in a backup routine.

The best backup of a VM is a shut-down VM, not paused or save-stated. Then simply copy the VM's folder containing the .vbox file and disk files and Snapshots folder. Also copy any disk files stored outside the VM's folder. If the VM's disk files are all under the VM folder with the .vbox file, then the backup copy can be dropped onto any capable Virtualbox host and started. If the VM's disk files are outside he VM folder, then manual editing of absolute disk file paths in the .vbox file might be necessary, but the VM can still be taken to another host without much trouble. This kind of backup also allows FC-file-comparing and hashing to confirm backup integrity and automatic confirmation of offsite copies of the backup.

If the VM must remain running while backing up, use inside-the-VM OS-native or 3rd-party backup software compatible with the services and databases the VM provides to back up to a shared folder on a different host or network drive.

A snapshotted VM basically locks the previous snapshot's or base disk's data in the middle of whatever the VM was doing (the VM OS does not know about this 'locking') and new data writes to the new snapshot disk. Dirty databases, partial open files, etc are on the locked disk, which gets backed up in the dirty state. Unsaved data in the VM does not get backed up. The restore process leaves you a VM in the same state as if it were unceremoniously powered off without shutdown at the moment of the snapshot. Data is corrupted and unreliable.

Copying only the VDIs leaves behind the .vbox file, which is the 'motherboard' of the VM and which can influence software licensing.

I have run scripted backups using full-shutdown FC'd and hashed copy of the VM folder & files, and in-the-VM backup software, with onsite and offsite confirmed backups, and the restores were 100% reliable.

One other thing:
JDaus wrote:Check if VM has live-backup config (not sure how to do this
See https://www.virtualbox.org/manual/ch08. ... stproperty
This can store custom keys and data in the VM's .vbox file, which both the host, and the VM via Guest Additions, can read and write.
Post Reply