Backup Scripts - Commands

This is for discussing general topics about how to use VirtualBox.
Post Reply
tremble
Posts: 10
Joined: 28. Sep 2010, 17:31
Primary OS: MS Windows 2008
VBox Version: OSE Debian
Guest OSses: XP, 7 and 2003, 2008

Backup Scripts - Commands

Post by tremble »

Sorry mods if this is not in the right area!... :D


am not a command guy at all..

here is what i have so far..

problem = i have a few vm that need backup

i would like a script or batch file that will shutdown the actual system,, do the clone vdi then once completed bring the system backup

if i can get 1 file to do that, i would be very very greatful.. i can then put that file in a schedule with microsoft scheduler..

if you can point me in the right direction i would appreciate it.


thanks everyone.. i have searched this forum and could not find that information!
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Backup Scripts - Commands

Post by Perryg »

You would need to create a batch file using VBoxManage commands to achieve this.
See http://www.virtualbox.org/manual/ch08.html for proper syntax and usage
tremble
Posts: 10
Joined: 28. Sep 2010, 17:31
Primary OS: MS Windows 2008
VBox Version: OSE Debian
Guest OSses: XP, 7 and 2003, 2008

Re: Backup Scripts - Commands

Post by tremble »

i will look it over.

ok, i have looked it over.. i have that same documentation. its really like reading japanese to me.

I was hopeing someone would have had it created and it would be available for download.

:mrgreen:
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Backup Scripts - Commands

Post by Perryg »

Where's the fun in that? Learning is part of the experience.
make a list of what needs to be done then convert each step to a command. Put this all in a batch file and run it.

Kind of like:
  • stop VM (replace with the command)
    clone vm (replace with the command)
    start vm (replace with the command)
Each of these steps are clearly laid out in the VBoxManage commands list.
tremble
Posts: 10
Joined: 28. Sep 2010, 17:31
Primary OS: MS Windows 2008
VBox Version: OSE Debian
Guest OSses: XP, 7 and 2003, 2008

Re: Backup Scripts - Commands

Post by tremble »

great info..

see i can understand that.

I will do what i think is what your saying, then i will copy it here. then maybe you can advise if it is correct :D
Rastus
Posts: 37
Joined: 13. Jan 2010, 04:19
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Windows

Re: Backup Scripts - Commands

Post by Rastus »

Also,
I believe that vboxtool offers some of that functionality as well as autostart of multiple machines and other useful items.

http://vboxtool.sourceforge.net/

I found that useful, you might too.
"Putting the FUN back in Dysfunctional"
tremble
Posts: 10
Joined: 28. Sep 2010, 17:31
Primary OS: MS Windows 2008
VBox Version: OSE Debian
Guest OSses: XP, 7 and 2003, 2008

Re: Backup Scripts - Commands

Post by tremble »

Can anyone put in a file or text here exactly the commands for stopping, cloning and then restarting again..

please use full path and only put "machine" where i would put my vm's names in where the quotes are. I really feel like 5 years old because everything i try i just cant figure it out!
antoniofr
Posts: 3
Joined: 22. Nov 2015, 17:36

Re: Backup Scripts - Commands

Post by antoniofr »

I use this method:

Download scripts here: http://www.michublog.com/informatica/sc ... de-windows


Method 1: poweroff VM and copy folder

Code: Select all

@ECHO OFF
CLS
 
SET "VM=Ubuntu Server 14.04"
SET "VM_DIR=C:\VirtualBox VMs\"
SET "BACKUP_DIR=C:\VirtualBox VMs\backup\"
SET VBOXMANAGE="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
SET RAR="C:\Program Files\WinRAR\Rar.exe"
SET CICLOS=10
SET PAUSAS=5
SET SOLICITUD_APAGADO=0
SET ERROR=0
SET RUNNING_INICIAL=2
 
ECHO Starting backup VM "%VM%"...
 
:check_running
%VBOXMANAGE% list runningvms > %TEMP%\runningvms.txt
FIND "%VM%" %TEMP%\runningvms.txt > nul
 
IF %errorlevel% EQU 0 (
    SET RUNNING=1
) ELSE (
    SET RUNNING=0
)
 
IF %RUNNING_INICIAL% EQU 2 (
    SET RUNNING_INICIAL=%RUNNING%
)
 
IF %CICLOS% GTR 0 (
    IF %RUNNING% EQU 1 (
        IF %SOLICITUD_APAGADO% EQU 0 (
            SET SOLICITUD_APAGADO=1
            ECHO Power off VM "%VM%"...
            %VBOXMANAGE% controlvm "%VM%" acpipowerbutton
        )
 
        ECHO Waiting VM "%VM%" shut down...
        TIMEOUT /t %PAUSAS% /nobreak > nul
        SET /a CICLOS-=1
        GOTO check_running
    ) ELSE (
        ECHO VM "%VM%" is power off now...
    )
)
 
DEL %TEMP%\runningvms.txt
 
IF %RUNNING% EQU 1 (
    SET ERROR=1
    GOTO end
)
 
:copy_vm
ECHO Copying VM "%VM%"...
TIMEOUT /t 3 /nobreak > nul
XCOPY "%VM_DIR%%VM%" "%BACKUP_DIR%%VM%" /E /I /Y
 
IF %errorlevel% NEQ 0 (
    SET ERROR=2
    GOTO end
)
 
:start_vm
IF %RUNNING_INICIAL% EQU 1 (
    ECHO Starting VM "%VM%"...
    %VBOXMANAGE% startvm "%VM%"
     
    IF %errorlevel% NEQ 0 (
        SET ERROR=3
        GOTO end
    )
)
 
:compress_backup
ECHO Compressing backup VM "%VM%"...
SET FECHA=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%
%RAR% a -r -ep1 -o+ "%BACKUP_DIR%%VM% %FECHA%.rar" "%BACKUP_DIR%%VM%"
 
IF %errorlevel% NEQ 0 (
    SET ERROR=4
    GOTO end
)
 
:delete_uncompressed_backup
ECHO Removing uncompressed backup VM "%VM%"...
RMDIR "%BACKUP_DIR%%VM%" /S /Q
 
IF %errorlevel% NEQ 0 (
    SET ERROR=5
    GOTO end
)
 
:end
IF %ERROR% GTR 0 (
    ECHO Error ^(%ERROR%^) while creating backup VM "%VM%".
) ELSE (
    ECHO Backup finished OK.
)
Method 2: save VM state and export to OVF and VMDK

Code: Select all

@ECHO OFF
CLS
 
SET "VM=Ubuntu Server 14.04"
SET "VM_DIR=C:\VirtualBox VMs\"
SET "BACKUP_DIR=C:\VirtualBox VMs\backup\"
SET VBOXMANAGE="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
SET ERROR=0
SET RUNNING_INICIAL=2
 
ECHO Starting backup VM "%VM%"...
 
:check_running
%VBOXMANAGE% list runningvms > %TEMP%\runningvms.txt
FIND "%VM%" %TEMP%\runningvms.txt > nul
 
IF %errorlevel% EQU 0 (
    SET RUNNING_INICIAL=1
) ELSE (
    SET RUNNING_INICIAL=0
)
 
DEL %TEMP%\runningvms.txt
 
IF %RUNNING_INICIAL% EQU 1 (
    ECHO Saving state VM "%VM%"...
    %VBOXMANAGE% controlvm "%VM%" savestate
 
    IF %errorlevel% NEQ 0 (
        SET ERROR=1
        GOTO end
    )
)
 
:export_vm
ECHO Exporting VM "%VM%"...
TIMEOUT /t 3 /nobreak > nul
SET FECHA=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%
%VBOXMANAGE% export "%VM%" -o "%BACKUP_DIR%%VM% %FECHA%.ovf"
 
IF %errorlevel% NEQ 0 (
    SET ERROR=2
    GOTO end
)
 
:start_vm
IF %RUNNING_INICIAL% EQU 1 (
    ECHO Starting VM "%VM%"...
    %VBOXMANAGE% startvm "%VM%"
     
    IF %errorlevel% NEQ 0 (
        SET ERROR=3
        GOTO end
    )
)
 
:end
IF %ERROR% GTR 0 (
    ECHO Error ^(%ERROR%^) while creating backup VM "%VM%".
) ELSE (
    ECHO Backup finished OK.
)
More info here: http://www.michublog.com/informatica/sc ... de-windows

I hope it helped.
Post Reply