I have written a batch file, the aim of the file is to stop vm, take a back up (Copy the entire Virtualbox VMs) folder to a different drive, start VMs.
Code is as below:
@echo on
cls
echo "Change directory to Virtualbox root directory"
cd /d "c:\Program Files\Oracle\VirtualBox"
echo "Powering off Virtual machines"
VBoxManage controlvm "centos74.master" poweroff
PING localhost -n 30 >NUL
VBoxManage controlvm "centos74.agent" poweroff
PING localhost -n 30 >NUL
echo "Commence backup work"
cd /d E:
if not exist Backup-%date:~-4,4%-%date:~-7,2%-%date:~-10,2% mkdir Backup-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%
REM cd Backup-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%
robocopy C:\Users\user\VirtualBox VMs\ E:\Backup-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%
echo "Change directory to Virtualbox root directory"
cd /d "c:\Program Files\Oracle\VirtualBox"
echo "Starting Virtual machines"
VBoxManage startvm "centos74.master"
PING localhost -n 30 >NUL
VBoxManage startvm "centos74.agent"
PING localhost -n 30 >NUL
@echo off
I however have two issues. 1. robocopy in itself doesn't work, please find below execution error message
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Tuesday, 20 November 2018 9:19:03 AM
Source - C:\Users\user\VirtualBox\
Dest - E:\VMs\
Files :
Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
ERROR : Invalid Parameter #3 : "E:\Backup-2018-11-20"
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.
For more usage information run ROBOCOPY /?
**** /MIR can DELETE files as well as copy them !
Not so important but still the below code is ineffective, meaning it should only create one and only folder even if you execute multiple times. When I execute multiple times it creates nested folder like
E:\Backup-20-Nov-2018\Backup-20-Nov-2018\Backup-20-Nov-2018\
Buggy code:
if not exist Backup-%date:~-4,4%-%date:~-7,2%-%date:~-10,2% mkdir Backup-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%
Any assistance will be greatly appreciated.