I currently use the following .cmd file to backup my RMS database. Once done I send the backup file to my backoffice file server.
:: Creates the newest backup on ONE (main server) from SQL query OSQL -U sa -P password -S servername -Q "BACKUP DATABASE [main] TO DISK 'c:\temp\rmsbackup.bck' WITH FORMAT, STATS"
However, I would like to take several backups during the day and would like to add a date and time stamp to the backup file name. I tried the following .cmd file but get some syntax errors with the + sign.
:: Creates the newest backup on ONE (main server) from SQL query OSQL -U sa -P password -S servername -Q "BACKUP DATABASE [main] TO DISK 'c:\temp\rmsbackup_' + str(year(getdate())) + str(month(getdate())) + str(day(getdate())) + str(datepart(hh,getdate())) + str(mi(getdate())) + str(datepart(ss,getdate())) + '.bck' WITH FORMAT, STATS"
I get the following errors:
Msg 170, Level 15, State 1, Server T42, Line 1 Line 1: Incorrect syntax near '+'.
I don't see anything wrong with the syntax but obviously there is.
Any help would be greatly appreciated.