Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-SQL: Manual Backup of Multiple Databases

$
0
0

I am looking to change the way I do manual backups of multiple databases on the same instance of SQL Server 2008 R2.

Currently I have T-SQL scripts for each database that look like this:

BACKUP DATABASE [mydbname] 
 TO DISK = N'D:\backup\manual\2014-01-01_1618\mydbname_2014-1-01_1618.bak' 
 WITH NOFORMAT,
 NOINIT,
 NAME = N'mydbname-Full Database Backup',
 SKIP,
 NOREWIND,
 NOUNLOAD,
 STATS = 10
GO

But there are six of these scripts, one for each database. Now in another language and my past programming experience I would just use an array of database names and a loop, so that BACKUP DATABASE would only exist once in the script, but be executed multiple times, once for each database name in the array.

I have such a very limited understanding of T-SQL, but I am guessing there is a completely different paradigm for the equivalent of, say, a for loop.

I'd also like a solution where the date_time directory for the output of each backup to be dynamically generated. Instead of having to pre-create the dirs myself.

Any help would be appreciated.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>