THIS IS A WINDOWS

exportVMs.cmd

SCRIPT, BUT CAN BE EASILY ADAPTED TO WORK UNDER LINUX:

you will have to make an entry for every vm.

PRINCIPLE:
1. SAVE STATE (PAUSE VM)
2. CLONE TO BACKUP DIRECTORY (preferable on a NAS with a lot of storage… like 5x 2TB RAID5)
3. START VM

REM net use B: \\192.168.0.251\backup /persistent:yes /user:backup password

SET BACKUPDIR=\\192.168.0.251\backup

ECHO "writing current date to variable"
SET DATE=%date:~6,4%-%date:~3,2%-%date:~0,2%

ECHO "going into virtualbox directory so VBoxManage.exe can be reached"
REM cd "C:\Program Files\Oracle\VirtualBox\"

ECHO "
===================================="

SET VNAME=NAME_OF_VM1

VBoxManage.exe controlvm "
%VNAME%" savestate

VBoxManage.exe clonevm --options keepallmacs "
%VNAME%" --name "%DATE%_%VNAME%" --basefolder %BACKUPDIR%

VBoxManage.exe startvm --type headless "
%VNAME%"

ECHO "
backup of "%VNAME%" FINISHED"

ECHO "
===================================="

SET VNAME=NAME_OF_VM2

VBoxManage.exe controlvm "
%VNAME%" savestate

VBoxManage.exe clonevm --options keepallmacs "
%VNAME%" --name "%DATE%_%VNAME%" --basefolder %BACKUPDIR%

VBoxManage.exe startvm --type headless "
%VNAME%"

ECHO "
backup of "%VNAME%" FINISHED"

ECHO "
===================================="

ECHO "
FINISHED"
admin