-2

I need a query that runs every day, and I want the query to make a .bak and name it according to the backup date.

Can someone lead me in the right direction? - Thanks!

BACKUP DATABASE [MYDB] TO  DISK = N'D:\SQL backups\SERVER1\12345.bak' WITH NOFORMAT, NOINIT,  NAME = N'MYDB-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO
Steve IT
  • 164
  • 1
  • 8
  • 1
    http://stackoverflow.com/questions/18437910/mysql-is-it-possible-to-backup-mysql-database-within-a-period-of-time – Avinash Babu Mar 11 '15 at 17:12

1 Answers1

0

I found the solution to my question by doing some research and I'd like to share it, so here it is:

DECLARE @SQLStatement VARCHAR(2000) 
SET @SQLStatement = N'D:\SQL backups\SERVER1\MYDB-' + CONVERT(nvarchar(30), GETDATE(), 110) +'.bak' 
BACKUP DATABASE [MYDB] TO  DISK = @SQLStatement

If you want to use this code, just replace file path to your own folder where you save SQL backups and replace every instance of "MYDB" with your database name. Also, change 'D:\SQL backups\SERVER1\MYDB' with your path. That's all! I hope this script can help many as it has helped me......

Steve IT
  • 164
  • 1
  • 8