Avatar of APD Toronto
APD Toronto
Flag for Canada

asked on 

MSSQL Backup

Hi Experts,

I have the following line in a batch file that it supposed to backup my MSSQL databases
sqlcmd -U sa -P xxx-S OPTIPLEX\SQLEXPRESS -i "D:\Scripts\MSSQL_Backup.sql" > "C:\Users\Nataliia & aleks\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\MSSQL_Results.txt"

Open in new window


the MSSQL_Backup.sql is
DECLARE @name VARCHAR(50) -- database name  
DECLARE @path VARCHAR(256) -- path for backup files  
DECLARE @fileName VARCHAR(256) -- filename for backup  
DECLARE @fileDate VARCHAR(20) -- used for file name
 
-- specify database backup directory
SET @path = 'D:\DBs_Backups\MSSQL\'  
 
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) 
 
DECLARE db_cursor CURSOR FOR  
SELECT name 
FROM master.dbo.sysdatabases 
WHERE name NOT IN ('master','model','msdb','tempdb')  -- exclude these databases
 
OPEN db_cursor   
FETCH NEXT FROM db_cursor INTO @name   
 
WHILE @@FETCH_STATUS = 0   
BEGIN   
       SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  
       BACKUP DATABASE @name TO DISK = @fileName  
 
       FETCH NEXT FROM db_cursor INTO @name   
END   
 
CLOSE db_cursor   
DEALLOCATE db_cursor

Open in new window


The MSSQL_Results.txt file is supposed to be as follows, with corresponding .BAK files for each database
Processed 13024 pages for database 'CSS_Reservations', file 'CSS_Reservations_dat' on file 1.
Processed 1 pages for database 'CSS_Reservations', file 'CSS_Reservations_log' on file 1.
BACKUP DATABASE successfully processed 13025 pages in 1.263 seconds (80.568 MB/sec).
Processed 192 pages for database 'CSSCharters_local', file 'CSSTChartes_local' on file 1.
Processed 1 pages for database 'CSSCharters_local', file 'CSSTChartes_local_log' on file 1.
BACKUP DATABASE successfully processed 193 pages in 0.218 seconds (6.916 MB/sec).
Processed 256 pages for database 'MYLA', file 'MYLA' on file 1.
Processed 1 pages for database 'MYLA', file 'MYLA_log' on file 1.
BACKUP DATABASE successfully processed 257 pages in 0.289 seconds (6.947 MB/sec).
Processed 4424 pages for database 'CSS_Carts', file 'CSSCarts_LIVE_Data' on file 1.
Processed 1 pages for database 'CSS_Carts', file 'CSSCarts_LIVE_Log' on file 1.
BACKUP DATABASE successfully processed 4425 pages in 0.647 seconds (53.431 MB/sec).
Processed 6944 pages for database 'MAS_BHE', file 'MAS_BHE' on file 1.
Processed 1 pages for database 'MAS_BHE', file 'MAS_BHE_log' on file 1.
BACKUP DATABASE successfully processed 6945 pages in 0.992 seconds (54.695 MB/sec).

Open in new window


I have running this daily, and for the past 1 year it has been flawless, but lately at least 3 times a week the results file is empty, and no .bak files, and no errors. How can I trace whats is going on?

I am running this on Windows 7 Pro and SQL server 2008 R2

Any help will be greatly appreciated.
Microsoft SQL Server 2008Microsoft SQL ServerWindows 7

Avatar of undefined
Last Comment
APD Toronto

8/22/2022 - Mon