My home server runs several services in a virtual machine with VirtualBox on Linux. Backups are mandatory and usually easy to achieve when using virtual machines. Just copy the files. To do this automatically I wrote a small backup batch file. My server runs Windows as host system.
The batch file pauses the virtual machine, saves the current state. Copies the files to an USB harddrive and restarts the VM after that:
"c:\Program Files\Oracle\VirtualBox\vboxmanage.exe" controlvm UbuntuServer savestate xcopy "C:\Users\da\VirtualBox VMs\UbuntuServer\*" e:\backup_vm\%date%\* /Y /S "c:\Program Files\Oracle\VirtualBox\vboxmanage.exe" startvm UbuntuServer
VirtualBox ships a small command line utility „vboxmanage.exe“. The tool can be found in the program folder of VirtualBox and offers a lot of control over VirtualBox and virtual maschines.
The first line stops the VM and saves the state.
vboxmanage.exe controlvm UbuntuServer savestate
„UbuntuServer“ is the name of the VM as it is labelled in the VirtualBox Manager software.
The second line is a simple xcopy command, which copies the VM over the the USB drive. %date% creates a folder with the current date. In case there are problems, I have multiple backups. This also means that I have to delete older backups from time to time, as the VM is around 20 GB in size currently. Xcopy has two parameters here „/S“ copies subfolders and „/Y“ deletes any file in the destination folder. Since I am using the current date, there should be no file to overwrite of course.
The third step resumes the VM. This batch file can now be called at night automatically.