<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[OCS Solutions Forums - Backing Up the Databases]]></title>
		<link>http://forums.ocssolutions.com/topic/15/backing-up-the-databases/</link>
		<description><![CDATA[The most recent posts in Backing Up the Databases.]]></description>
		<lastBuildDate>Fri, 15 Jan 2010 07:10:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/48/#p48</link>
			<description><![CDATA[<div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p>Now that the website is set up to automatically back up the MySQL databases, I just have to figure out a way to automate the download of the backup files to my computer.</p></blockquote></div><p>There&#039;s 2 ways to do this.</p><p>If you&#039;re using Linux or a Mac, you can use rsync to download files:</p><div class="codebox"><pre><code>rsync -av cpuser@yoursite.com:/home/cpuser/backup/yourbackupfile.tar.gz /home/yourlocaluser/wherever</code></pre></div><p>Just add a cronjob for this and you&#039;re done.</p><p>If you&#039;re using Windows, you have 2 options.&nbsp; Install <a href="http://www.cygwin.com/">Cygwin</a> to get access to the rsync and crontab commands (probably best method long term), or use a program like <a href="http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp">DeltaCopy</a>.</p>]]></description>
			<author><![CDATA[dummy@example.com (rob)]]></author>
			<pubDate>Fri, 15 Jan 2010 07:10:20 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/48/#p48</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/47/#p47</link>
			<description><![CDATA[<div class="quotebox"><cite>rob wrote:</cite><blockquote><div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p>Do you know how to set up a script to automatically delete the old database backup copies when they get x-days old. (or however that might be done.)</p></blockquote></div><p>You can use find and xargs like this:</p><div class="codebox"><pre><code>cd ~/your-backups ; find -atime 5 | xargs rm</code></pre></div><p>to delete files created more than 5 days ago.</p></blockquote></div><p>Hi Rob,<br />Thank you very much for giving me that script. It is a great beginning point!</p><p>I tested your script using PuTTy and found that it deleted my backups that were only 3 days old, which wasn&#039;t what I wanted. So I searched the Internet and found this page about <a href="http://www.beginlinux.com/desktop_training/comm/admincommands/292-find">FIND</a>. I had to make a slight change to your script.&nbsp; The &quot;-&quot; before <span class="bbu">atime</span> means it would find any files <span class="bbu">less</span> than 5 days old. I then change the script to be like this:<br /></p><div class="codebox"><pre><code>cd ~/db-backups ; find +atime 5 | xargs rm *.gz</code></pre></div><p>The &quot;*.gz&quot; at the end means that it will find all the files that end in &quot;.gz&quot;.</p><p>It tested that code again using PuTTy, and it worked fine. It deleted all the files ending in .gz that were older than 5 days.</p><p>Then I created a file in ~/bin that I named &quot;RemoveOldMySQL-backups.sh&quot;. This is the contents of the file:<br /></p><div class="codebox"><pre><code>#!/bin/sh
# change directory to home/db-backups
# find all files ending in .gz that are over 30 days old and remove (delete) them
cd ~/db-backups ; find +atime 30 | xargs rm *.gz</code></pre></div><p>This code should find and delete all .gz files that are older than 30 days.</p><p>I then set up a cron job.....<br /></p><div class="codebox"><pre><code>30      0      1,15      *      *       ~/bin/RemoveOldMySQL-backups.sh</code></pre></div><p>... to activate tha &quot;RemoveOldMySQL-backups.sh&quot; file twice a month, on the 1st and on the 15th of each month</p><p>I&#039;ll just need to check on the backup files, on the website and on my computer, now and then to make sure they continue to work as they are supposed to work.</p><br /><p>Now that the website is set up to automatically back up the MySQL databases, I just have to figure out a way to automate the download of the backup files to my computer.</p><p>Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Wed, 13 Jan 2010 18:48:29 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/47/#p47</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/46/#p46</link>
			<description><![CDATA[<div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p>The gzipped file is about 1/5 to 1/8 of the regular .sql backup file. Does that sound about right, about the gzipped file being so much smaller than the .sql file?</p></blockquote></div><p>Yes.&nbsp; SQL dump files are usually just text, so they compress very well.</p><div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p>Do you know how to set up a script to automatically delete the old database backup copies when they get x-days old. (or however that might be done.)</p></blockquote></div><p>You can use find and xargs like this:</p><div class="codebox"><pre><code>cd ~/your-backups ; find -atime 5 | xargs rm</code></pre></div><p>to delete files created more than 5 days ago.</p><div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p>Thank you so much for all the help that you&#039;ve given me.</p></blockquote></div><p>Not a problem, we&#039;re here to help!</p>]]></description>
			<author><![CDATA[dummy@example.com (rob)]]></author>
			<pubDate>Wed, 13 Jan 2010 03:38:30 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/46/#p46</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/45/#p45</link>
			<description><![CDATA[<p>Hi Robert,<br />&nbsp; &nbsp;Thank you very much for your help. I followed your instructions in the previous message, corrected the .my.cnf file to include the cpanelusername and cpanelpassword, changed the database backup script to get rid of the username and password, and got the got the backup script to work by entering&nbsp; &quot;~/bin/MySQL-DatabaseBackups.sh*&quot; into the PuTTy command line.<br />(*MySQL-DatabaseBackups.sh is the name of my backup script).</p><p>I have the script set up like this for each database.<br /></p><div class="codebox"><pre><code>mysqldump  cpaneluser_databasename | gzip &gt; ~/db-backups/database-`date +%m-%d-%Y`.sql.gz</code></pre></div><p>It creates a backup like this: databasename-01-01-2010.sql.gz for each database.<br />the gzipped file is about 1/5 to 1/8 of the regular .sql backup file. Does that sound about right, about the gzipped file being so much smaller than the .sql file?</p><p>I still have to do some tests on importing the gzipped backup files into some database files to make sure that they work.</p><p>Then corrected my entry in cron to use &quot;~/bin/MySQL-DatabaseBackups.sh&quot;</p><p>Using your instructions above, I&#039;ve appended the date to the database backup name. I did a test run, via Putty, to verify that it worked, and it does. Next I&#039;ve also change the cron job run to once a week, for now, so it won&#039;t fillup the disk space so rapidly.</p><div class="codebox"><pre><code>0      0      *      *      0       ~/bin/MySQL-DatabaseBackups.sh</code></pre></div><p>Do you know how to set up a script to automatically delete the old database backup copies when they get x-days old. (or however that might be done.)</p><p>Robert. Thank you so much for all the help that you&#039;ve given me.</p><p>Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Fri, 01 Jan 2010 09:26:07 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/45/#p45</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/44/#p44</link>
			<description><![CDATA[<p>The correct format of the file is:</p><div class="codebox"><pre><code>[client]
user = cpaneluser
password = cpaneluserpw</code></pre></div><p>Replace <strong>cpaneluser</strong> with your cPanel/FTP/SSH username, and <strong>cpaneluserpw</strong> with the password to that user.&nbsp; To ensure it has secure permissions, run in shell:</p><div class="codebox"><pre><code>chmod 0600 ~/.my.cnf</code></pre></div><p>Once you&#039;ve done that, you can test it my simply running:</p><div class="codebox"><pre><code>mysql</code></pre></div><p>Once you do that, you should see something similar to:</p><div class="codebox"><pre><code>Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 546048
Server version: 5.0.87-community-log MySQL Community Edition (GPL)

Type &#039;help;&#039; or &#039;\h&#039; for help. Type &#039;\c&#039; to clear the current input statement.

mysql&gt;</code></pre></div><p>which means its working.&nbsp; You can then run mysqldump commands without user and password parameters, like:</p><div class="codebox"><pre><code>mysqldump dbname &gt; dbname.sql</code></pre></div><p>and it should work fine.</p>]]></description>
			<author><![CDATA[dummy@example.com (rob)]]></author>
			<pubDate>Fri, 01 Jan 2010 00:21:58 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/44/#p44</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/43/#p43</link>
			<description><![CDATA[<p>Hi Rob,<br />&nbsp; &nbsp;I&#039;ve tried to use the a bunch of times to use a script with the .my.cnf file, but I must be doing something wrong.<br />I created a test script called &quot;dbtest.sh&quot;</p><div class="codebox"><pre><code>#!/bin/sh
mysqldump -e -u databaseuser databasename1 &gt; ~/db-backups/databasename1.sql
mysqldump -u databaseuser databasename2 &gt; ~/db-backups/databasename2.sql

# mysqldump -e -u yourcpuser yourdbname &gt; ~/db-backups/yourdbname.sql

# mysqldump -u USER -p DATABASE &gt; filename.sql</code></pre></div><p><em>(The bottom two (commented out) lines are for my reference, one line of instructions from you and one from another place.)</em></p><p>I created this .my.cnf file first.</p><div class="codebox"><pre><code>[client]
user = databaseusername
password = databasepassword</code></pre></div><p>When I still&nbsp; permission denied errors, I change the .my.cnf to this: </p><div class="codebox"><pre><code>[client]
user = databaseusername
password = databasepassword
host = Localhost</code></pre></div><p>When I have more time, I&#039;ll go through it again. At this point I still just don&#039;t understand how it is supposed to work and what to do. I don&#039;t have any more time to work on it tonight.</p><p>More later,<br />Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Thu, 31 Dec 2009 07:07:56 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/43/#p43</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/42/#p42</link>
			<description><![CDATA[<div class="quotebox"><cite>rob wrote:</cite><blockquote><p>I strongly recommend using the ~/my.cnf file instead of putting the password in your script.&nbsp; When doing this, you can use the &#039;mysql&#039; command without having to enter the password either.&nbsp; If you ever change your password you&#039;ll just have to change it in one place and not modify your script.&nbsp; Plus this file is more secure since its permissions are only 0600.</p></blockquote></div><p>Hi Robert,<br />&nbsp; &nbsp;I think you have convinced me that I shoul dus the my.cnf file, I don&#039;t know how to use it. Did you explain it already, or give me a link to it already and I just missed it? If you&nbsp; haven&#039;t explained it, could you give me a link or tell me how to use it?&nbsp; I&#039;ll look again through your messages, etc, when I get time. If I don&#039;t find anything, I&#039;ll do some more searching on the internet to see if I can find info about how to use a my.cnf file.</p><p>Thanks for you advice. Much appreciated.</p><p>Edit: I looked back in this message&nbsp; thread at the info you gave about the my.cnf file. I don&#039;t understand how to use it. So I looked on the Internet and found this page: <a href="http://www.modwest.com/help/kb6-242.html">How do I create a .my.cnf MySQL preference file?</a>. I&#039;ll read it over a little later. It looks promising.</p><p>Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Thu, 31 Dec 2009 05:25:29 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/42/#p42</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/41/#p41</link>
			<description><![CDATA[<div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p><span class="bbu"><strong>Robert, thank you so very much for helping me to get transferred to you servers and helping me to get started in this new way of doing things.</strong></span> In the end I can see that this will be much simpler to keep the website files backed up.</p></blockquote></div><p>No problem!&nbsp; Glad to help.</p><div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p><strong>WISH LIST</strong><br />Here are some things I still hope to do.<br /></p><ul><li><p>I still want to change the download directory that PSFTP downloads to on my computer.</p></li><li><p>I&#039;d like to figure out a way to automatically have the backup files downloaded onto my computer. I just found a website that might be able to help me figure this out:&nbsp; <a href="http://www.robvanderwoude.com/ftp.php#UnattendedFTP">Creating Unattended FTP Scripts</a>. I still have to read it over and possibly do some experimenting.</p></li><li><p>I&#039;d also like to figure out how to have the date appended to the MySQL backup files when they are created on the server. </p></li><li><p>I will probably set up ways to back up the other files in my account (such as the various Drupal and image files) </p></li><li><p>I may have others things to add here as I remember them.</p></li></ul></blockquote></div><p>For automatic downloads to your computer, check out rsync.&nbsp; It&#039;s not for Windows, so you&#039;ll have to use Cygwin.&nbsp; &nbsp;Setting this up is beyond the scope of this post, but you can use SSH keys with that, so you won&#039;t have to enter a password, and rsync downloads only what has changed, saving bandwidth and time.</p><p>You can append the date using something like this:</p><div class="codebox"><pre><code>mysqldump dbname &gt; dbname1-`date +%m-%d-%Y`</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (rob)]]></author>
			<pubDate>Wed, 30 Dec 2009 23:54:57 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/41/#p41</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/40/#p40</link>
			<description><![CDATA[<div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p><strong>The ~/.my.cnf File</strong><br /></p><div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p><strong>My.Cnf File</strong><br />Then I created a ~/.my.cnf in my home directory and entered this info into it.<br /></p><div class="codebox"><pre><code>[client]
user =   databaseuser
password = databasepassword</code></pre></div><p>I gave this file permissions of 0600</p></blockquote></div><p>With the way that I have cron set up, I don&#039;t see that this <strong>~/.my.cnf</strong> file is of any use. Do I really need this file?</p><p>Best Wishes,<br />Stephen</p></blockquote></div><p>Steve,</p><p>I strongly recommend using the ~/my.cnf file instead of putting the password in your script.&nbsp; When doing this, you can use the &#039;mysql&#039; command without having to enter the password either.&nbsp; If you ever change your password you&#039;ll just have to change it in one place and not modify your script.&nbsp; Plus this file is more secure since its permissions are only 0600.</p>]]></description>
			<author><![CDATA[dummy@example.com (rob)]]></author>
			<pubDate>Wed, 30 Dec 2009 23:50:58 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/40/#p40</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/39/#p39</link>
			<description><![CDATA[<p>I don&#039;t have time to examine it closely right now, but I think I found some info about making a script to delete old backup files here:&nbsp; <a href="http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html">4.5.4. mysqldump — A Database Backup Program</a></p><p>I don&#039;t know if I got all the necessary code from that page (If necessary, I&#039;ll look more later), but here is a sample of the code I found:<br /></p><div class="codebox"><pre><code># DO NOT DELETE AUTOMATICALLY FOR NOW, MAYBE LATER

DELETE_EXPIRED_AUTOMATICALLY=&quot;TRUE&quot;

# DELETE EXPIRED BACKUPS THAT ARE MORE THAN
# expire_minutes=$(( 1 * 30 )) # 30 minutes old
# expire_minutes=$(( 60 * 24 )) # 1 day old
# expire_minutes=$(( 60 * 24 * 7 )) # 7 days old
# expire_minutes=$(( 60 * 24 * 30 )) # 30 days old

expire_minutes=$(( 60 * 24 * 7 )) # 7 days old

if [ $expire_minutes -gt 1440 ]; then
    expire_days=$(( $expire_minutes /1440 ))
else
    expire_days=0
fi</code></pre></div><p>....and I found a little more code on this page: <a href="http://dev.mysql.com/doc/refman/4.1/en/mysqldump.html">4.5.4. mysqldump — A Database Backup Program</a> (Don&#039;t know if any of it will be useful, but I&#039;ll look at it when I have a little more time.</p><div class="quotebox"><blockquote><p>Posted by Julien GARINO on December 17 2009 7:57am</p><p><em>You always wanted to BACKUP your most important database somewhere in your Linux system, as well as send the dump by email, so that you can recover the entire content if the system crashes.<br />You can use these 2 scripts.</em></p><p><em>First Step:<br />-Install the mutt client that will transfer emails on the command-line : &quot;apt-get install mutt&quot; or &quot;yum install mutt&quot;<br />-Create the backup directory : &quot;mkdir /home/backups&quot;</em></p><p><em>Second Step:<br />- Copy these 2 scripts on your root directory or your user directory :</em></p><div class="codebox"><pre><code>#!/bin/sh
# Script name : auto_mysql_dump.sh
# Backup the dbname database
dir=`date +%Y-%m-%d`
dbname=`mybase`</code></pre></div><p><em>...... there is more code below this, but no need to copy that here.</em></p></blockquote></div><p>Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Tue, 29 Dec 2009 16:15:58 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/39/#p39</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/38/#p38</link>
			<description><![CDATA[<div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p><strong>WISH LIST</strong><br />Here are some things I still hope to do.<br /></p><ul><li><p>I&#039;d also like to figure out how to have the date appended to the MySQL backup files when they are created on the server. </p></li></ul></blockquote></div><p><strong>Just a note:</strong> I found some of the things on my wish list: <br />--&gt;On this web page <a href="http://www.ducea.com/2006/10/28/compressing-mysqldump-output/">Compressing mysqldump output</a> I found a way to compress the output of the MySqlDump files.&nbsp; I have already added this to my backup script.<br />--&gt;On this web page: <a href="http://railsrant.com/2009/08/26/backing-up-mysql-on-the-crontab-with-a-shell-script">Backing up MySQL on the crontab with a shell script</a> is a way to append the date to the MySqlDump backup files. The output file looks like this: &quot;FileName_�Dec-29-09�.sql&quot;. <span class="bbu">However, before I use this, I need to find a script that will delete the saved files after x-days, otherwise the backup files could fill up the disk space</span>.</p><br /><p>Although thebelow message didn&#039;t give the script, the idea given here <em>(of totally automatic database backups, compression (&amp; my date added to file name), and automatic download to my computer)</em> is something like what I had in mind, with perhaps some variations:<br /><a href="http://www.webmasterworld.com/forum10/4013.htm">Looking for MySQL Backup program</a><br /></p><div class="quotebox"><cite>Shady wrote:</cite><blockquote><p>If you have shell access you could write a simple script (or get someone to write it for you) like the one I have written which does the following:</p><p>mysqldump (as mentioned above)<br />gzip (to compress)<br />ftp (copy backup offsite)</p><p>This script is scheduled using cron the run every 12 hours on my machine.</p></blockquote></div><br /><br /><br /><p>Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Tue, 29 Dec 2009 15:52:20 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/38/#p38</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/37/#p37</link>
			<description><![CDATA[<h5>Lastest Report</h5><p>Hi Robert,<br />&nbsp; Just a note to let you know that I finally have Putty with the SSH Keys set up and working.<br />I have set automatic login (without having to enter the passphrase each time) by setting that up in Pageant. So now I can just start Putty and it automatically logs in.<br />I&#039;ve also learned to use Putty PSFTP. It also automatically logs in without having to enter a password or passphrase. I&#039;ve learned that I can just FTP all the MySQL backup files from the website home/db-backups directory to my computer by just changing directories ~/db-backups and then entering &quot;mget *.sql&quot; into the&nbsp; Putty PSFTP terminal window. </p><p><strong>RECAP</strong><br />So, as a recap: All the dabases are automatically backed up into the ~/db-backups directory each night. (I might end up changing that to once every few days or once a week. But I decide that later.)</p><p>Then, all I have to do is run the PuTTy PSFTP program, when it logs into my website home directory, change directory to&nbsp; ~/db-backups and enter &quot;mget *.sql&quot; and all the databases are downloaded into the My Documents folder.</p><p>Although it was quite a bit of work and quite a challenge for me, this new way is <span class="bbu">so much simpler and quicker</span>&nbsp; than my old way to backup the databases.</p><p><span class="bbu"><strong>Robert, thank you so very much for helping me to get transferred to you servers and helping me to get started in this new way of doing things.</strong></span> In the end I can see that this will be much simpler to keep the website files backed up.</p><p><strong>WISH LIST</strong><br />Here are some things I still hope to do.<br /></p><ul><li><p>I still want to change the download directory that PSFTP downloads to on my computer.</p></li><li><p>I&#039;d like to figure out a way to automatically have the backup files downloaded onto my computer. I just found a website that might be able to help me figure this out:&nbsp; <a href="http://www.robvanderwoude.com/ftp.php#UnattendedFTP">Creating Unattended FTP Scripts</a>. I still have to read it over and possibly do some experimenting.</p></li><li><p>I&#039;d also like to figure out how to have the date appended to the MySQL backup files when they are created on the server. </p></li><li><p>I will probably set up ways to back up the other files in my account (such as the various Drupal and image files) </p></li><li><p>I may have others things to add here as I remember them.</p></li></ul><br /><p>Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Mon, 28 Dec 2009 17:05:11 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/37/#p37</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/36/#p36</link>
			<description><![CDATA[<p><strong>The ~/.my.cnf File</strong><br /></p><div class="quotebox"><cite>StephenW wrote:</cite><blockquote><p><strong>My.Cnf File</strong><br />Then I created a ~/.my.cnf in my home directory and entered this info into it.<br /></p><div class="codebox"><pre><code>[client]
user =   databaseuser
password = databasepassword</code></pre></div><p>I gave this file permissions of 0600</p></blockquote></div><p>With the way that I have cron set up, I don&#039;t see that this <strong>~/.my.cnf</strong> file is of any use. Do I really need this file?</p><p>Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Mon, 28 Dec 2009 05:10:41 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/36/#p36</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/35/#p35</link>
			<description><![CDATA[<p>Hi Rob,<br />I&#039;m still trying to get this to work:</p><p>To see what I might have done wrong, and to see if I could set up a cron job using Putty, I decided to use the code you supplied, and then to try out some modifications<br />First I connected with PuTTy and entered this code<br /></p><div class="codebox"><pre><code>crontab -e</code></pre></div><p>Then from the next window I entered this code:<br /></p><div class="codebox"><pre><code>10 * * * * /home/winterss/bin/db-backup</code></pre></div><p>That didn&#039;t work.</p><p><strong>A Successful Test on PuTTy</strong><br />After some trial and error, I finally came up with this code. I pasted this into Putty....<br /></p><div class="codebox"><pre><code>~/bin/MySQL-db-backups.sh</code></pre></div><p>.... and it executed my &quot;MySQL-db-backups.sh&quot; script file, I saw that it had worked. (I check in the db-backups folder and found that it made a backup of all my MySQL databases.) Now I&#039;ll set up a cron job and test that out.</p><p>I created this cron job to test it out. I think that this is set to run every 5 minutes, so that I don&#039;t have to wait as long to see if it works.<br /></p><div class="codebox"><pre><code>5      *      *      *      *       ~/bin/MySQL-db-backups.sh</code></pre></div><p>That didn&#039;t work, so I created another cron job:</p><p><strong>SUCCESS!!!</strong><br />I set up this cron job to run every 5 minutes.....<br /></p><div class="codebox"><pre><code>*/5      *      *      *      *       ~/bin/MySQL-db-backups.sh</code></pre></div><p>.... and found that it exported the copies into the ~/db-backups folder as it was supposed to. I let it run twice and then changed it to run once a day. </p><p>This is what the final cron job looks like.<br /></p><div class="codebox"><pre><code>0      21      *      *      *       ~/bin/MySQL-db-backups.sh</code></pre></div><p>Am I correct in assuming that it will just overwrite the backup files each day?</p><p>This has been a looong day. I spent some hours figuring this out. (probably someone who knew what they were doing could have done it in only a few minutes.). Anyway, I feel good that I got this step finished.</p><p><strong>Now, the next questions:</strong><br />1.) Is it possible to have each database backup file have the date appended to the end of the name (so that the backups don&#039;t overwrite the existing backups), and then to have it automatically delete the previous backups that are more than x-days old (so that the backups don&#039;t fill up the disk space)?<br />2.) Is it possible to have those backup files automatically downloaded and backed up on my computer.</p><p>Bests Wishes,<br />Stephen </p><p>Best Wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Mon, 28 Dec 2009 05:06:31 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/35/#p35</guid>
		</item>
		<item>
			<title><![CDATA[Re: Backing Up the Databases]]></title>
			<link>http://forums.ocssolutions.com/post/34/#p34</link>
			<description><![CDATA[<p><strong>Below is what I&#039;ve done up to this point:</strong><br />I did all the following inside the cPanel Files directories:</p><p><strong>Script File</strong><br />I created a folder in the home directory named &quot;bin&quot;<br />I created the script file in the ~/bin folder and named it &quot;MySQL-db-backups.sh&quot;, and then pasted this script into it. <em>(I pasted my actual database names and passwords into the actual file instead of those shown here)</em><br /></p><div class="codebox"><pre><code>#!/bin/sh
mysqldump -u databaseusername -pdatabasepassword databasename1 &gt; ~/db-backups/dumpfilename1.sql
mysqldump -u databaseusername -pdatabasepassword databasename2 &gt; ~/db-backups/dumpfilename2.sql
mysqldump -u databaseusername3 -pdatabasepassword databasename3 &gt; ~/db-backups/dumpfilename3.sql
mysqldump -u databaseusername4 -pdatabasepassword databasename3 &gt; ~/db-backups/dumpfilename4.sql
mysqldump -u databaseusername5 -pdatabasepassword databasename3 &gt; ~/db-backups/dumpfilename5.sql
mysqldump -u databaseusername6 -pdatabasepassword databasename3 &gt; ~/db-backups/dumpfilename6.sql
mysqldump -u databaseusername7 -pdatabasepassword databasename3 &gt; ~/db-backups/dumpfilename7.sql</code></pre></div><p>I gave the &quot;MySQL-db-backups.sh&quot; file permissions of 0755</p><p>Created a folder in the home directory of ~/db-backups&nbsp; with permissions of 0755.</p><p><strong>My.Cnf File</strong><br />Then I created a ~/.my.cnf in my home directory and entered this info into it.<br /></p><div class="codebox"><pre><code>[client]
user =   databaseuser
password = databasepassword</code></pre></div><p>I gave this file permissions of 0600</p><p><strong>Cron Job Test</strong><br />Since I didn&#039;t know how else to test the script, I set up this temporary&nbsp; cronjob to run every 10 minutes. (which is a short enough time to see if it will actually work.)<br /></p><div class="codebox"><pre><code>*/10      *      *      *      *       wget ~bin/MySQL-db-backups.sh &gt;/dev/null</code></pre></div><p>As I waited about 30 minutes (as I wrote out this message), I kept checking the <strong>~/db-backups</strong> folder (where the backups should be going). However, the folder is still empty, so obviously I&#039;m doing something wrong.&nbsp; I then deleted that cron job.</p><p><strong>What am I doing wrong? What am I missing?</strong></p><p>Best wishes,<br />Stephen</p>]]></description>
			<author><![CDATA[dummy@example.com (StephenW)]]></author>
			<pubDate>Mon, 28 Dec 2009 02:35:38 +0000</pubDate>
			<guid>http://forums.ocssolutions.com/post/34/#p34</guid>
		</item>
	</channel>
</rss>
