I have two batch files.
First extracts date from and creates folder in \YEAR\MONTH\DATE format.
@echo off
setlocal enabledelayedexpansion
:: Extract date fields
for /f "tokens=1-4 delims=/-. " %%i in ('date /t') do (
set v1=%%i& set v2=%%j& set v3=%%k
if "%%i:~0,1%%" gtr "9" (set v1=%%j& set v2=%%k& set v3=%%l)
for /f "skip=1 tokens=2-4 delims=(-)" %%m in ('echo.^|date') do (
set %%m=!v1!& set %%n=!v2!& set %%o=!v3! ))</br>
:: Final set for language independency
set year=%yy%%aa%
set month=%mm%
set day=%dd%
:: Make Dir
set root=f:\
::Create folder of today's date
if exist %root% goto L2
goto L3
:L2
if not exist %root%\%year% md %root%\%year%
:L3
if exist %root%\%year%\%month% goto L5
:L4
if not exist %root%\%year%\%month% md %root%\%year%\%month%
:L5
md %root%\%year%\%month%\%day%
:: Detete folder older than '3' days
forfiles /p "%root%%year%\%month%" /s /d -3 /c "cmd /c IF @isdir == TRUE rd /S /Q @path"
echo.
pause
creates a backup of database
echo off
cls
echo -- BACKUP DATABASE --
::set db name
set DATABASENAME='db_name'
:: set path and format
set BACKUPFILENAME='path\%DATABASENAME%.bak'
:: set server name
set SERVERNAME='server name'
echo.
::backup execution
sqlcmd -S %SERVERNAME% -Q "BACKUP DATABASE [%DATABASENAME%] TO DISK = N'%BACKUPFILENAME%' WITH INIT , NOUNLOAD , NAME = N'%DATABASENAME% backup', NOSKIP , STATS = 10, NOFORMAT"
echo.
Now I want to call the second batch file from first and also pass the parameters like root, year, month, date from first to second. I've tried both codes individually and its working perfectly. How can I pass the parameters. Please help
If you call second batch from first one, something like
call backupDP.cmd
both files share the same environment, so, both see the same variables. No need to pass anything, the second batch already has all the data.