I'm trying to create a batch file which will backup data to a date stamped folder and then when needed will be able to restore the data from the most recent backup. I can get the .bat to create the folder and backup the data needed from the set variables. The problem is when I want to do an incremental backup or restore that data from the previous day. I get an error telling me the date cannot be found. I can't for the life of me figure out how to make it look for the most recent backup and then do an incremental or restore. I was searching online for ages yesterday and found nothing of use.
I hope that makes some sense.
It's been doing my nut in for 2 days now and all I need it to do is look for the latest backup and let me do an incremental to it or restore from it. Any help or ideas would be great.
Edit: I've hard coded it to backup/restore My Documents so if you run this .bat please remember to change it to something more suitable to you.
Code:
@ECHO OFF
REM These are the variables for the backup drive
SET drive=c:\Backup
SET backcmd=xcopy /e/w/h/v
SET incrcmd=xcopy /e/w/h/d/v
SET restcmd=xcopy /e/w/h/v
SET date="%date:~0,2%-%date:~3,2%-%date:~6,6%"
GOTO MENU
:MENU
ECHO Please choose a command by pressing numbers 1-4
ECHO 1 Full backup of "My Documents"
ECHO 2 Incremental backup of "My Documents"
ECHO 3 Restore "My Documents"
ECHO 4 Quit
set /P N=Type 1, 2, 3 or 4 then press ENTER:
IF "%N%"=="1" GOTO BACK
IF "%N%"=="2" GOTO INCR
IF "%N%"=="3" GOTO REST
IF "%N%"=="4" GOTO QUIT
IF NOT "%N%"=="1,2,3,4" GOTO STOP
:BACK
echo ## Backup of the "My Documents" folder to "C:\Backup"
%backcmd% "%USERPROFILE%\My Documents" "%drive%\%date%"
ECHO You will now be returned to the menu screen
pause
cls
goto menu
:INCR
echo ## Incremental backup of the "My Documents" folder to "C:\Backup"
%incrcmd% "%USERPROFILE%\My Documents" "%drive%\%date%"
ECHO You will now be returned to the menu screen
pause
cls
goto menu
:REST
echo ## Restore files from "C:\Backup" folder to "My Documents"
%restcmd% "%drive%\%date%" "%USERPROFILE%\My Documents"
pause
cls
goto menu
:QUIT
ECHO The program will now close
pause
exit
:STOP
ECHO **This is not a valid command**
ECHO you will now be returned to the menu screen
pause
cls
GOTO MENU
I hope that makes some sense.

Edit: I've hard coded it to backup/restore My Documents so if you run this .bat please remember to change it to something more suitable to you.