I am fairly new to writing .sql files to run with sqlcmd.
I have a SQL Express server with a few database files on the server and i was hoping someone could help with writing a .sql file which i can then get the task scheduler to execute say every 3 hours.
this is what i have at the moment
sqlcmd -S CPCTRACKING\SQLEXPRESS -E -i c
:\progra~1\datash~1\dssql.sql -o c:\sql_backups\Bck_Log.txt
In my dssql.sql file i have
BACKUP DATABASE [db1] TO DISK='c:\SQL_backups\db1.bak' WITH INIT
BACKUP DATABASE [db2] TO DISK='c:\SQL_backups\db2.bak' WITH INIT
BACKUP DATABASE [db3] TO DISK='c:\SQL_backups\db3.bak' WITH INIT
What i would liek to do is first when the script runs, to delete and files in the destination folder older than 48 hrs. Then add to the .bak file a date and time stamp for example
s this possible?