Get Date in batch file (Virtual PC) and use the variable in xcopy /D:date

394 Views Asked by At

I need to schedule a daily save from a virtual machine running on Dos 6.22, and to do so I need to stock the date variable and use it to do a differential backup. Otherwise the backup operation would take too much time, since it will copy the same files again and again.

I tried everything and apparently the date variable isn't available in this version, and if I want to manage variables I need to do it in a separate batch file.

I tried the robocopy, but then again it isn't available for this version of Dos.

Is there anyone who could help me with this ? It's been a week since i've been working on this.

Cheers,

2

There are 2 best solutions below

0
On

Thank you everyone for your answers, I finally did it. I didn't use any of the solutions above since it doesn't work on MS.DOS 6.22

I just created a script in the real machine :

set day=%date:~,2%
set /a day=day-1
set mydate=%date:~3,2%-%jour%-%date:~6,4%
echo xcopy /D:%mydate% /Y c:\log z:\logs>copylog.bat

This script creates a batch file with the following instruction :

xcopy /D:%mydate% /Y c:\log z:\logs>copylog.bat

Where mydate is yesterday's date. And I run this script from the virtual machine.

To keep mydate updated I scheduled a task to run the first script everyday at midnight.

This might help someone with the same kind of problem I got.

0
On

To get the date into a variable is nearly easy.

You need a template file (_Date.tmp) with exactly one line without a new line, containing:

set date=

Then you could use it in your batch file (main.bat) like

copy _date.tmp _date.bat
ver | date | find "date is" >> myDate.bat
call myDate.bat
echo The date is: %date%

But then you have to split the string (Today's date is 20/01/2015) in the variable.

That is a bit more tricky, but can be done ...