<?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>Admin Reports &#187; batch file</title>
	<atom:link href="http://adminreports.com/tag/batch-file/feed/" rel="self" type="application/rss+xml" />
	<link>http://adminreports.com</link>
	<description>Resources for Server and Forum Admins that run Windows Servers and IIS.</description>
	<lastBuildDate>Sun, 18 Jul 2010 14:00:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Batch File to Backup Your Windows Server Database</title>
		<link>http://adminreports.com/batch-file-to-backup-your-windows-server-database/</link>
		<comments>http://adminreports.com/batch-file-to-backup-your-windows-server-database/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 18:15:27 +0000</pubDate>
		<dc:creator>BSchwarz</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[batch file]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[windows server]]></category>

		<guid isPermaLink="false">http://adminreports.com/batch-file-to-backup-your-windows-server-database/</guid>
		<description><![CDATA[If you read <a href="http://adminreports.com/backing-up-your-data/">Backing up Your Data with cwRsync and snyc2nas</a> you learned how to send your data to an off site server. Now I'll show you a couple ways to make incremental zipped backups that you can store on your server to transfer with sync2nas or FTP the backup to your home box.]]></description>
			<content:encoded><![CDATA[<p>If you read <a href="http://adminreports.com/backing-up-your-data/">Backing up Your Data with cwRsync and snyc2nas</a> you learned how to send your data to an off site server. Now I&#8217;ll show you a couple ways to make incremental and dated zipped backups that you can store on your server to transfer with sync2nas or FTP the backup to your home box.</p>
<p>I&#8217;ll attach the batch files at the end of the post for those that don&#8217;t want to copy and paste the code. Now lets get started.</p>
<p><span id="more-34"></span></p>
<p>For the first method you&#8217;ll need the batch file and a text file with you FTP login information and you&#8217;ll need a command line zip program. You can use <a href="http://www.winzip.com/prodpagecl.htm">Winzip Command Line Tools</a> if you have Winzip installed on the sever or<a href="http://www.7-zip.org/">7zip</a> if you have it installed. I use GNU Gzip, you download it at the projects <a href="http://gnuwin32.sourceforge.net/packages/gzip.htm">Sourceforge</a> page, so this tutorial will be specific to it.</p>
<p>First the batch file to create the backup.</p>
<p>Copy and paste this into your text editor and save as mysql-ftp.bat:</p>
<blockquote><p>@ECHO OFF</p>
<p>@REM Set directory variables.<br />
SET basedir=C:\Backup<br />
SET workdir=C:\Temp<br />
SET mysqldir=C:\path\to\mysql\bin<br />
SET gzipdir=C:\PROGRA~1\GnuWin32\bin<br />
SET mysqlpassword=mysqlpassword<br />
SET mysqluser=mysqluser</p>
<p>@REM Change to mySQL directory<br />
CD %mysqldir%</p>
<p>@REM dump all databases.<br />
mysqldump -u %mysqluser% -p%mysqlpassword% &#8211;all-databases &gt;%workdir%\backup.sql</p>
<p>@REM Change to working directory<br />
CD %workdir%</p>
<p>@REM Zip up databases<br />
%gzipdir%\gzip.exe backup.sql</p>
<p>@REM Chage the file name to a random name<br />
MOVE backup.sql.gz backup.%random%.gz</p>
<p>@REM FTP file offsite<br />
FTP -n -s:%basedir%\ftp.txt</p>
<p>@REM Remove old backup files<br />
del backup.sql<br />
del backup.*.gz</p>
<p>@REM Change back to base dir<br />
CD %basedir%</p></blockquote>
<p>Some notes on the above.</p>
<ul>
<li>basedir is the directory you are launching the batch file from.</li>
<li>workdir is the temp directory where the files are stored until the job is done.</li>
<li>mysqldir is where your mysql binaries are.</li>
<li>gzipdir is where you installed GNU gzip and this is default for the installer so no need to change it.</li>
<li>mysqlpassword is the password to connect to mysql.</li>
<li>mysqluser is mysql usr tht can connect to mysql.</li>
</ul>
<p>Once the backup is made and FTP was sent the script will delete the backup file. If you want to keep the backups it created remove these lines.<br />
<code><br />
@REM Remove old backup files<br />
del backup.sql<br />
del backup.*.gz<br />
</code></p>
<p>If you want to backup only one database instead of all of them change this line:<br />
<code><br />
mysqldump -u %mysqluser% -p%mysqlpassword% --all-databases &gt;%workdir%\backup.sql<br />
</code><br />
To This:<br />
<code><br />
mysqldump -u %mysqluser% -p%mysqlpassword% databasename &gt;%workdir%\backup.sql<br />
</code><br />
If you noticed this line,<br />
<code><br />
FTP -n -s:%basedir%\ftp-commands.txt<br />
</code><br />
You&#8217;ll now need the contents of the FTP script which you will place in the basedir where the batch file is. Here it is.<br />
<code><br />
open<br />
<a href="ftp://ftp.yourftpserver.com" style="color: #006620; background-color: #fff9ab" class="linkification-ext" title="Linkification: ftp://ftp.yourftpserver.com">ftp.yourftpserver.com</a><br />
user<br />
username<br />
password<br />
bin<br />
put backup.*.gz<br />
quit<br />
</code></p>
<p>That&#8217;s it. Copy the batch file code, make any of the changes outlined above and call it backuptoftp.bat and copy the FTP script and name it ftp.txt.</p>
<p>Read on and I&#8217;ll give you another example that will make a date based backup and store it on your server for later transfer.</p>
<p>&nbsp;</p>
<p><br />
<script type="text/javascript"><!--
google_ad_client = "pub-2292466120976221";
/* Admin Reports Posts */
google_ad_slot = "2391864490";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://adminreports.com/batch-file-to-backup-your-windows-server-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
