<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Edwin M Sarmiento&gt;Lazy DBA: Backup all your databases using a script &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/lazy-dba-backup-all-your-databases-using-a-script/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>&gt;Lazy DBA: Backup all your databases using a script</title>
		<link>https://www.edwinmsarmiento.com/lazy-dba-backup-all-your-databases-using-a-script/</link>
		<comments>https://www.edwinmsarmiento.com/lazy-dba-backup-all-your-databases-using-a-script/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 23:37:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2007/12/14/lazy-dba-backup-all-your-databases-using-a-script</guid>

				<description><![CDATA[&#62;I have a compilation of scripts which I use on a daily basis to help me make my work a bit easier. I always mention during my presentations that the laziest people are administrators who happen to have a programming background. Here&#8217;s one that I frequently use. A message on my instant messenger popped up [&#8230;]]]></description>
					<content:encoded><![CDATA[<p>&gt;<span style="font-family:arial;">I have a compilation of scripts which I use on a daily basis to help me make my work a bit easier. I always mention during my presentations that the laziest people are administrators who happen to have a programming background. Here&#8217;s one that I frequently use. A message on my instant messenger popped up asking me how to quickly perform backups of databases in SQL Server. I told him to write a <strong><span style="font-size:85%;">BACKUP DATABASE</span></strong> command. Now, he was telling me about how much time it would take since they have like hundreds of databases. The solution: write a script. The script below performs a backup of all the databases on a SQL Server 2000 instance and dumps it in a local folder.</span><br /><span style="font-family:Arial;"></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>DECLARE @IDENT INT, @sql VARCHAR(1000), @DBNAME VARCHAR(200)<br />SELECT @IDENT=MIN(DBID) FROM SYSDATABASES WHERE [DBID] &gt; 0 AND NAME NOT IN (&#8216;PUBS&#8217;, &#8216;NORTHWIND&#8217;, &#8216;TEMPDB&#8217;)</strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>WHILE @IDENT IS NOT NULL</strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>BEGIN </strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>SELECT @DBNAME = NAME FROM SYSDATABASES WHERE DBID = @IDENT</strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>/*Change disk location here as required*/ </strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>SELECT @SQL = &#8216;BACKUP DATABASE </strong></span><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>&#8216; + @DBNAME + &#8216;</strong></span><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong> TO DISK = &#8221;FBACKUP&#8217;+@DBNAME+&#8217;.BAK&#8221; WITH INIT, STATS=10&#8242; </strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>PRINT &#8220;===========================================&#8221; </strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>EXEC (@SQL) </strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>PRINT &#8220;Backup for database &#8221; + @DBNAME + &#8221; has been created&#8221; </strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>SELECT @IDENT=min(DBID) FROM SYSDATABASES WHERE [DBID] &gt; 0 AND DBID&gt;@IDENT AND NAME NOT IN (&#8216;PUBS&#8217;, &#8216;NORTHWIND&#8217;, &#8216;TEMPDB&#8217;)</strong></span><br /><span style="font-family:lucida grande;font-size:85%;color:#000099;"><strong>END</strong></span></p>
<p><span style="font-family:arial;">This excludes the tempdb, Northwind and Pubs databases should you have it in your instance. Restoring is, of course, a different story.  You need to start with the system databases (master and msdb, in my case) before you can restore the user databases.  In a future blog post, I&#8217;ll have a script to read the backups generated by this script and restore them all. See how lazy I can be?</span></p>
<div class="blogger-post-footer"><img width='1' height='1' src='' alt='' /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/lazy-dba-backup-all-your-databases-using-a-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">57</post-id>	</item>
	</channel>
</rss>