In below code I want to create a daily wise folder with hostname for backup where the date format shall be MM.dd.yyyy.
I'm using set mydate=%date:/=% and Echo %mydate% to get thedate. But I'm getting dd-MM-yyyy format.
As the system format is dd-MM-yyyy %date% not providing desired format.
My script so far:
@echo off
REM Getting Host Name
FOR /F "usebackq" %%i IN (hostname) DO SET host=%%i
ECHO %host%
REM Getting System Date & Time
set mydate=%date:/=%
Echo %mydate%
set mytime=%time:~-11,2%-%time:~-8,2%-%time:~-5,2%
set mytimestamp=%mydate: =%%mytime:.=%
echo %mytimestamp%
REM This timestamp is used to create folder System Name with date
set mynewtimestamp=%host%%mydate: =%
echo %mynewtimestamp%
Rem Change the WINRAR Installation path & MSSQL OSQL.exe path in below statement, seperated with semicolumn.
set path=C:\Program Files\WinRAR;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\WINDOWS\System32;
Rem Change patch in following statement as per Required "BackupDest1" (Centrlise Location) Installation.
set BackupDest=D:\Daily_Backup\Backup\
REM CREATING BACKUP WITH RAR FORMAT
rar a -ep1 "%BackupDest%%mytimestamp%_TEST.rar" "C:\Program Files\TEST"
REM MSSQL DB BACKUP
"osql.exe" -E -Q "BACKUP DATABASE [TEST] TO DISK='%BackupDest%%mytimestamp%_MSSQL_TEST.bak' WITH FORMAT"
rar a -epl "%BackupDest%%mytimestamp%_SQL_Backup.rar" "%BackupDest%*.bak"
pushd "%BackupDest%"
del .bak
del .reg
md %BackupDest%%mynewtimestamp% 2>NUL
ROBOCOPY "D:\Daily_Backup\Backup" "%BackupDest%%mynewtimestamp%" /z /MOV /MT32