Exporting doesn't work from Task Scheduler

Discussions related to using VirtualBox on Windows hosts.
Post Reply
FlashT
Posts: 3
Joined: 5. Dec 2022, 15:00

Exporting doesn't work from Task Scheduler

Post by FlashT »

I got a .bat script that contains:

Code: Select all

ECHO ON
C:
cd "C:\Program Files\Oracle\VirtualBox"

for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set dow=%%i
set month=%%j
set day=%%k
set year=%%l
)
set datestr=%year%-%month%-%day%

THEN

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" export Debian -o "E:\AUTOBACKUP\%datestr%.ova" >> E:\log.txt

When I run it manually (from Task Scheduler or directly) it works fine. But when it's being triggered from Task Scheduler automatically, it only creates 13kB ova file... why is that? how to fix/debug it? Run with highest privileges option is checked. Also run whenever user is logged in or not.

PS. Log.txt contains nothing new. But when it was successful on running manually, it wrote "Successfully exported 1 machine(s)." to the log.txt file.
PPS. I also tried using start command, but it did not help. In fact it was even worse, nothing was happening.
PPPS. Is OVA file enough to backup whole machine with additional drive attached?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Exporting doesn't work from Task Scheduler

Post by scottgus1 »

First things first:
FlashT wrote:Is OVA file enough to backup whole machine
No. Exporting changes the VM's files: disk format type to vmdk, UUIDs get changed which may interfere with licensing on import restore, snapshots are merged. Changed files cannot be integrity-checked against the original, so you don't know if the backup worked.

Back up by standard file copy of the whole VM folder and external disk files, while the VM is fully shut down not save-stated. Then FC file-compare to check backup integrity.
FlashT wrote:When I run it manually (from Task Scheduler or directly) it works fine. But when it's being triggered from Task Scheduler automatically, it only creates 13kB ova file... why is that?
It probably happens because the account the auto task trigger is using is not the account the Debian VM is stored under.

Virtualbox defaults to storing its config files in the logged-on user's account folders. So if you log in as 'A', the VM info gets stored in C:\Users\A\.Virtualbox. Log in as 'B', and Virtualbox will look in C:\Users\B\.Virtualbox for the configuration. It won't find A's VM configuration.

The file-copy backup routine above is not subject to account limitations, as long as the account used can access the VM files.

Also, I'd put the log in a different folder than the root of a drive. Windows has special permissions for drive roots that may cause trouble one day.
FlashT
Posts: 3
Joined: 5. Dec 2022, 15:00

Re: Exporting doesn't work from Task Scheduler

Post by FlashT »

scottgus1 wrote: Back up by standard file copy of the whole VM folder and external disk files, while the VM is fully shut down not save-stated.
Could You please tell me how to do it automaticaly every week?
Last edited by mpack on 6. Dec 2022, 11:48, edited 2 times in total.
Reason: Trim unnecessary verbatim quote.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Exporting doesn't work from Task Scheduler

Post by mpack »

Copying files on the host OS is done outside of VirtualBox. It's up to you to learn your host OS. I'm sure Google can be a great resource on how to schedule regular tasks in Windows hosts.
FlashT
Posts: 3
Joined: 5. Dec 2022, 15:00

Re: Exporting doesn't work from Task Scheduler

Post by FlashT »

Yes, but can I close the machine and rerun automatically? To copy the files.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Exporting doesn't work from Task Scheduler

Post by scottgus1 »

Yes.

vboxmanage controlvm "VM name" acpipowerbutton

^ simulates a power button tap on the VM. If the VM OS is configured to auto shut down when the power button is tapped, this will shut down the VM correctly from within the VM OS.

vboxmanage showvminfo "VM name" | find "State:                       powered off"

^ in a script loop, this will wait until the VM window disappears. Use this to tell when the VM is completely shut down. (There are spaces between "State:" and "powered off".)

Research how to copy files/folders and file-compare in a script for your host OS.

vboxmanage startvm "VM name"

^ this restart the VM.

Strong recommendation: Do not under any circumstances go anywhere near considering a "backup" routine that uses snapshots. Such will leave you with a "backup" copy that is really a power-cut OS with dirty and incomplete files & databases. Thus the quotes around a snapshot-based "backup", which it is not.
Post Reply