I am using this batch file to backup all the databases in my sql server except those shipped with sql server,
@ECHO OFF
SETLOCAL
REM Get date in format YYYY-MM-DD (assumes the locale is the United States)
FOR /F “tokens=1,2,3,4 delims=/ ” %%A IN (‘Date /T’) DO SET NowDate=%%D-%%B-%%C
REM Build a list of databases to backup
SET DBList=%SystemDrive%SQLDBList.txt
SqlCmd -E -S MY-PC\SQLEXPRESS -h-1 -W -Q “SET NoCount ON; SELECT Name FROM master.dbo.sysDatabases WHERE [Name] NOT IN (‘master’,’model’,’msdb’,’tempdb’)” > “%DBList%”
REM Backup each database, prepending the date to the filename
FOR /F “tokens=*” %%I IN (%DBList%) DO (
ECHO Backing up database: %%I
SqlCmd -E -S MY-PC\SQLEXPRESS -Q “BACKUP DATABASE [%%I] TO Disk=’D:\SQLdata\Backup\%NowDate%_%%I.bak'”
ECHO.
)
REM Clean up the temp file
IF EXIST “%DBList%” DEL /F /Q “%DBList%”
ENDLOCAL
I have got the server name by using the query - SELECT @@SERVERNAME
just in case and the path is exactly the same.
I have run it manually and through windows task scheduler with Administrator permission, but I am not getting any back ups in the specified folder. I don't know what is wrong I am doing here. I am quite new to this stuff, please if anybody know then guide me, thanks.