<?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>Technology: Learn and Share &#187; Data Backup</title>
	<atom:link href="http://crazytoon.com/category/data-backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://crazytoon.com</link>
	<description>Enterprise level solutions, LAMP, Linux, Apache, MySQL, PHP, Perl, Windows, Cache, Optimization</description>
	<lastBuildDate>Fri, 16 Jul 2010 20:24:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL:  How do you set up master-slave replication in MySQL? (CentOS, RHEL, Fedora)</title>
		<link>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/</link>
		<comments>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 03:12:57 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[MySQL cluster]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/</guid>
		<description><![CDATA[Before we go into how to set up master-slave replication in MySQL, let us talk about some of the reasons I have set up master-slave replication using MySQL.
1)    Offload some of the queries from one server to another and spread the load:  One of the biggest advantages to have master-slave set [...]]]></description>
			<content:encoded><![CDATA[<p>Before we go into how to set up master-slave replication in MySQL, let us talk about some of the reasons I have set up master-slave replication using MySQL.</p>
<p>1)    Offload some of the queries from one server to another and spread the load:  One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts and send some, if not all, select queries to slave.  This will most probably speed up your application without having to diving into optimizing all the queries or buying more hardware.</p>
<p>2)    Do backups from slave:  One of the advantages people overlook is that you can use MySQL slave to do backups from.  That way site is not affected at all when doing backups.  This becomes a big deal when your database has grown to multiple gigs and every time you do backups using mysqldump, site lags when table locks happen.  For some sites, this could mean that site goes down for few secs to minutes.  If you have slave, you just take slave out of rotation (should be built into code) and run backups off the slave.  You can even stop slave MySQL instance and copy the var folder instead of doing mysqldump.</p>
<p>Ok let us dive into how to setup master-slave replication under MySQL.  There are many configuration changes you can do to optimize your MySQL set up.  I will just touch on very basic ones to get the replication to work.  Here are some assumptions:</p>
<blockquote><p>Master server ip:  10.0.0.1<br />
Slave server ip:  10.0.0.2<br />
Slave username:  slaveuser<br />
Slave pw:  slavepw<br />
Your data directory is:  /usr/local/mysql/var/</p></blockquote>
<p>Put the following in your master my.cnf file under [mysqld] section:</p>
<p><code># changes made to do master<br />
server-id           = 1<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
log-bin             = /usr/local/mysql/var/mysql-bin<br />
# end master</code></p>
<p>Copy the following to slave&#8217;s my.cnf under [mysqld] section:</p>
<p><code># changes made to do slave<br />
server-id           = 2<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
# end slave setup</code></p>
<p>Create user on master:<br />
<code>mysql&gt; grant replication slave on *.* to slaveuser@'10.0.0.2' identified by 'slavepw';</code></p>
<p>Do a dump of data to move to slave<br />
<code>mysqldump -u root --all-databases --single-transaction --master-data=1 &gt; masterdump.sql</code></p>
<p>import dump on slave<br />
<code>mysql &lt; masterdump.sql</code></p>
<p>After dump is imported go in to mysql client by typing mysql.  Let us tell the slave which master to connect to and what login/password to use:<br />
<code>mysql&gt; CHANGE MASTER TO MASTER_HOST='10.0.0.1',  MASTER_USER='slaveuser', MASTER_PASSWORD='slavepw';</code></p>
<p>Let us start the slave:<br />
<code>mysql&gt; start slave;</code></p>
<p>You can check the status of the slave by typing<br />
<code>mysql&gt; show slave status\G</code></p>
<p>The last row tells you how many seconds its behind the master.  Don’t worry if it doesn’t say 0, the number should be going down over time until it catches up with master (at that time it will show Seconds_Behind_Master: 0)  If it shows NULL, it could be that slave is not started (you can start by typing:  start slave) or it could be that it ran into an error (shows up in Last_errno: and Last_error under show slave status\G).</p>
<p>Related posts:</p>
<ul>
<li><a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" title="How do I dump all tables in a database into separate files?" target="_blank">How do I dump all tables in a database into separate files?</a></li>
<li><a href="http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/" title="How do I import individual table dump files in to MySQL using shell script?" target="_blank">How do I import individual table dump files in to MySQL using shell script?</a></li>
<li><a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL backups using mysqldump" target="_blank">MySQL backups using mysqldump</a></li>
</ul>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do I dump all tables in a database into separate files?</title>
		<link>http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/</link>
		<comments>http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 00:22:53 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/</guid>
		<description><![CDATA[There have been numerous occasions where I needed to make backups of individual tables from selected database.  Usually I can achieve this by typing:
mysqldump database_name table1 &#62; table1.sql
mysqldump database_name table2 &#62; table2.sql

This could be very painful if you have 10’s or 100’s of tables. Until today, I never ran into a situation where I [...]]]></description>
			<content:encoded><![CDATA[<p>There have been numerous occasions where I needed to make backups of individual tables from selected database.  Usually I can achieve this by typing:</p>
<p><code>mysqldump database_name table1 &gt; table1.sql<br />
mysqldump database_name table2 &gt; table2.sql<br />
</code><br />
This could be very painful if you have 10’s or 100’s of tables. Until today, I never ran into a situation where I had to deal with dumping more than few tables at a time.   Today I had to do a dump of 181 tables.  I was not going to sit there and type in that command with 181 table names.  It is not just time consuming but it is also stupid.  So I wrote this script to help me with this task.  We still use mysqldump command as described above, except we do it programmatically to make it easier on us:</p>
<p><code>#!/bin/bash<br />
db=$1<br />
if [ "$db" = "" ]; then<br />
echo "Usage: $0 db_name"<br />
exit 1<br />
fi<br />
mkdir $$<br />
cd $$<br />
clear<br />
for table in `mysql $db -e 'show tables' | egrep -v 'Tables_in_' `; do<br />
echo "Dumping $table"<br />
mysqldump --opt -Q $db $table &gt; $table.sql<br />
done<br />
if [ "$table" = "" ]; then<br />
echo "No tables found in db:  $db"<br />
fi</code></p>
<p>You can also compress your files by adding bzip2, zip or any other compression commands after mysqldump command.  Here is the same script with bzip2 command added:<br />
<code>#!/bin/bash<br />
db=$1<br />
if [ "$db" = "" ]; then<br />
echo "Usage: $0 db_name"<br />
exit 1<br />
fi<br />
mkdir $$<br />
cd $$<br />
clear<br />
for table in `mysql $db -e 'show tables' | egrep -v 'Tables_in_' `; do<br />
echo "Dumping $table"<br />
mysqldump --opt -Q $db $table &gt; $table.sql<br />
bzip2 $table.sql<br />
done<br />
if [ "$table" = "" ]; then<br />
echo "No tables found in db:  $db"<br />
fi</code></p>
<p>I do not recommend doing compression on a production server since most compression program put descent amount of load on the server.  Also note that this will delay your dump considerably.  You may also want to use different parameters for running mysqldump.  Type <a href="http://www.lamp-tips.com/man-pages/mysqldump/" title="man mysqldump - man page for mysqldump" target="_blank"><code>man mysqldump</code></a> in your shell to read more.</p>
<p>Related posts:</p>
<ul>
<li><a href="http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/" target="_blank" title="MySQL database backup file compress gzip vs bzip2">MySQL database backup file compress gzip vs bzip2</a></li>
<li><a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL backups using mysqldump" target="_blank">MySQL backups using mysqldump</a></li>
</ul>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>MySQL:  InnoDB: ERROR: the age of the last checkpoint is [number]</title>
		<link>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/</link>
		<comments>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 21:32:59 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/</guid>
		<description><![CDATA[One of the mysql database servers I manage started to have issues with doing backups yesterday.  mysqldump was running but nothing was happening on the backup side.  I started to investigate to see why our full backups were failing.  I opened up the mysql error log file (mine is at:  /usr/local/mysql/var/hostname.err) [...]]]></description>
			<content:encoded><![CDATA[<p>One of the mysql database servers I manage started to have issues with doing backups yesterday.  mysqldump was running but nothing was happening on the backup side.  I started to investigate to see why our full backups were failing.  I opened up the mysql error log file (mine is at:  /usr/local/mysql/var/hostname.err) and notice there were many instances of following error.</p>
<p><code>070815 15:31:46  InnoDB: ERROR: the age of the last checkpoint is 9433957,<br />
InnoDB: which exceeds the log group capacity 9433498.<br />
InnoDB: If you are using big BLOB or TEXT rows, you must set the<br />
InnoDB: combined size of log files at least 10 times bigger than the<br />
InnoDB: largest such row.</code></p>
<p>I poked around and found out our log files were set to default (5 mb) and they needed to be increased.  After doing some calculations and research, I decided going to 50 mb at this point would be a good way to go.   So I made the change in my.cnf file and added:  <code>innodb_log_file_size = 50M </code></p>
<p>I then stopped our mysql server and restarted it.  And to my horror I saw following error messages show up in the mysql error logs:</p>
<p><code>070815 17:37:40 [ERROR] /usr/local/mysql/libexec/mysqld: Incorrect information in file: './dbname/table_name.frm'<br />
070815 17:37:40 [ERROR] /usr/local/mysql/libexec/mysqld: Incorrect information in file: './dbname/table_name.frm'</code></p>
<p>I stopped the mysql server right away.  I then remember, by help of a friend, that I have to remove the old log files if I change the size by changing <code>innodb_log_file_size</code>.  So I issued a command:  <code>mv ib_logfile? ..</code></p>
<p>This command moves both ib_logfile1 and ib_logfile2 down one directory.  I didn&#8217;t want to just remove &#8216;em so instead I moved them.  After that, I restarted mysql again and to my comfort, everything came back up without errors.  So lesson learned:  if you change ib_logfile size by using  <code>innodb_log_file_size</code> setting, make sure you move existing log files before you start mysql again.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Apache:  How do you set up log rotation and archiving for Apache logs?</title>
		<link>http://crazytoon.com/2007/05/31/apache-how-do-you-set-up-log-rotation-and-archiving-for-apache-logs/</link>
		<comments>http://crazytoon.com/2007/05/31/apache-how-do-you-set-up-log-rotation-and-archiving-for-apache-logs/#comments</comments>
		<pubDate>Thu, 31 May 2007 23:53:39 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/05/31/apache-how-do-you-set-up-log-rotation-and-archiving-for-apache-logs/</guid>
		<description><![CDATA[If you have a website and never have archived your apache logs, you may be surprised one day by running out of space due to logs using up all the free space on specific partition. Most people don&#8217;t think about archiving until it is too late. Here we set up a simple log rotation script [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a website and never have archived your apache logs, you may be surprised one day by running out of space due to logs using up all the free space on specific partition. Most people don&#8217;t think about archiving until it is too late. Here we set up a simple log rotation script which will work for apache 1.x and also for apache 2.x version as well. I have included comments in the script itself to help you understand what is going on throughout.</p>
<p><code>#!/bin/sh<br />
#<br />
# Created by:  Sunny Walia<br />
# Date created:  5/24/03<br />
# Date Modified:  5/29/07<br />
# Purpose:  do any type of preprocessing before log.php can do its work.<br />
#           Also does log rotation and backup.<br />
#<br />
# Modification history:<br />
#   5/25/03:    added comments.<br />
#               Gzip and move to backup logs folder<br />
#               added config info on top<br />
#<br />
#<br />
# configuration info<br />
SERVERNAME="svr1"<br />
WORKINGDIR="/admin/backups/$SERVERNAME/logs/"<br />
BACKUPLOGSDIR="/admin/backups/$SERVERNAME/logs/archived/"<br />
BACKUP_DIR="/admin/backups/$SERVERNAME/"<br />
LOGDIR="/usr/local/apache2/logs/"<br />
DATE=`date +%m%d%y%H`<br />
APACHCTL_LOC="/usr/local/apache2/bin/"<br />
#<br />
mkdir $WORKINGDIR -p<br />
mkdir $BACKUPLOGSDIR -p<br />
mkdir $BACKUP_DIR -p<br />
#<br />
# move the logs into their temp name so apache can continue to write to it<br />
mv ${LOGDIR}access_log ${LOGDIR}${SERVERNAME}_access_log.old<br />
mv ${LOGDIR}error_log ${LOGDIR}${SERVERNAME}_error_log.old<br />
#<br />
# restart apache gracefully so it will finish what its doing and start a new log file<br />
# when done serving current requests<br />
${APACHCTL_LOC}apachectl graceful<br />
#<br />
# give some time to apache to finish serving pending requests (in secs)<br />
sleep 15<br />
#<br />
# copy the files to our directory for processing<br />
cp ${LOGDIR}${SERVERNAME}_access_log.old ${WORKINGDIR}${SERVERNAME}_access_log<br />
cp ${LOGDIR}${SERVERNAME}_error_log.old ${WORKINGDIR}${SERVERNAME}_error_log<br />
#<br />
mv ${LOGDIR}${SERVERNAME}_access_log.old ${LOGDIR}${SERVERNAME}_access_log.$DATE<br />
mv ${LOGDIR}${SERVERNAME}_error_log.old ${LOGDIR}${SERVERNAME}_error_log.$DATE<br />
gzip ${LOGDIR}${SERVERNAME}_access_log.$DATE<br />
gzip ${LOGDIR}${SERVERNAME}_error_log.$DATE<br />
#<br />
# we move instead of copy than delete since if mv fails, we still have originals<br />
# mv can fail if target location is full<br />
mv ${LOGDIR}${SERVERNAME}_access_log.$DATE.gz $BACKUPLOGSDIR<br />
mv ${LOGDIR}${SERVERNAME}_error_log.$DATE.gz $BACKUPLOGSDIR<br />
</code></p>
<p>Let us make the script executable:<br />
<code>chmod +x  script_name.sh</code></p>
<p>You can automate this to happen every day by putting it in your crontab:<br />
<code>crontab -e</code></p>
<p><code>1 0 * * * /path/to/this/script</code></p>
<p>This will rotate your logs at 12:01 AM every day.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/05/31/apache-how-do-you-set-up-log-rotation-and-archiving-for-apache-logs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rsync:  Using rsync to backup data from one server to another over SSH.  Quick rsync tutorial.</title>
		<link>http://crazytoon.com/2007/05/24/rsync-using-rsync-to-backup-data-from-one-server-to-another-over-ssh-quick-rsync-tutorial/</link>
		<comments>http://crazytoon.com/2007/05/24/rsync-using-rsync-to-backup-data-from-one-server-to-another-over-ssh-quick-rsync-tutorial/#comments</comments>
		<pubDate>Thu, 24 May 2007 22:30:05 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[Windows System]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/05/24/rsync-using-rsync-to-backup-data-from-one-server-to-another-over-ssh-quick-rsync-tutorial/</guid>
		<description><![CDATA[Rsync is a great tool which can be used to do many tasks which involved copying/moving data.  If privacy/security is of concern, which it always should be, you can use rsync to do all the copying/moving of data over SSH.  Read through &#8220;man rsync&#8221; to get deeper understanding of rsync.  Here is [...]]]></description>
			<content:encoded><![CDATA[<p>Rsync is a great tool which can be used to do many tasks which involved copying/moving data.  If privacy/security is of concern, which it always should be, you can use rsync to do all the copying/moving of data over SSH.  Read through &#8220;man rsync&#8221; to get deeper understanding of rsync.  Here is my attempt to a short <strong>tutorial on rsync</strong>.   Let us start with most simple example of using rsync over ssh.</p>
<p><code> rsync -ae ssh server1:/home /home/backups/server1_home_backup/</code></p>
<p>This command will download all the files/directories from /home on server1 and copies them to /home/backups/server1_home_backup/<br />
-a = archive mode.  This will preserve permissions, timestamps, etc.<br />
-e = specify which remote shell to use.  In our case, we want to use ssh which follow right after  &#8220;e&#8221;</p>
<p>Let us improve on this and add couple more parameters:</p>
<p><code>rsync -zave ssh --progress server1:/home /home/backups/server1_home_backup/</code><br />
-z = adds zip compression.<br />
-v = verbose<br />
&#8211;progress = my favorite parameter when I am doing rsync manually, not so good when you have it in cron.  This show progress (how_many_files_left/how_many_files_total) and speed along with some other useful data.</p>
<p>Great.. we are moving along pretty good.  Let us add some security to make sure things work the way we want to.</p>
<p><code>rsync --delete-after -zave ssh --progress server1:/home /home/backups/server1_home_backup/</code></p>
<p>&#8211;delete-after = this will delete files on backup server which are missing from source <em>after</em> ALL syncing is done.  If you don&#8217;t care of having extra files on your backup server and have plenty of disk space to spare, do not use this parameter.</p>
<p>Lastly, one of the VERY handy parameters,</p>
<p><code>rsync --delete-after -zave ssh --progress server1:/home /home/backups/server1_home_backup/ -n</code></p>
<p>The -n (or &#8211;dry-run) parameter is great to use for testing.  It will not transfer or delete any files, rather will report to you what it would have done if it was ran with out -n parameter.  This way you can test it with out destroying or transfering data just to find out that is not what you wanted.</p>
<p>For further reading:  <a href="http://www.lamp-tips.com/man-pages/rsync/" title="man rsync - man page for rsync" target="_blank">man rsync</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/05/24/rsync-using-rsync-to-backup-data-from-one-server-to-another-over-ssh-quick-rsync-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL:  ibdata files do not shrink on database deletion [innodb]</title>
		<link>http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/</link>
		<comments>http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 23:07:03 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[innodb]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/</guid>
		<description><![CDATA[One very interesting thing I noticed with MySQL was that if you delete a database, ibdata file doesn&#8217;t shrink by that much space to minimize disk usage.  I deleted the database and checked usage of /usr/local/mysql/var folder and noticed that ibdata file is still the same size.  So the problem I face now [...]]]></description>
			<content:encoded><![CDATA[<p>One very interesting thing I noticed with MySQL was that if you delete a database, ibdata file doesn&#8217;t shrink by that much space to minimize disk usage.  I deleted the database and checked usage of /usr/local/mysql/var folder and noticed that ibdata file is still the same size.  So the problem I face now is, how do I claim back this space?</p>
<p>After searching for a bit on google about this problem, apparently only way you can do that is by exporting your mysql databases, delete ibdata1 file, import databases.  This creates new ibdata file with correct space usage.  Atleast there is a way to get around this issue.  But honestly, too much pain on production boxes where we might be trying to remove old databases to reclaim some of the hard drive space.</p>
<p>An preventive measure one can use is to use option: <code>innodb_file_per_table</code> (&#8216;put innodb_file_per_table&#8217; in your my.cnf file under [mysqld] section).  This will create individual files for tables under database directory.  So now when I delete the database, all the space is returned since the directory is now deleted along with database along with all the tables inside the directory.  In my test after you put option <code>innodb_file_per_table </code>your my.cnf, you will have to still do export/import to be able to minimize disk usage and have the ability to delete database at your leisure without worrying about reclaiming the disk space.  Here are the steps I took.  DISCLAIMER:  Please make backup of your data and use following steps at your own risk.  Doing it on test server is <strong>HIGHLY</strong> recommended.  Please don&#8217;t come back and tell me that you lost your data because you followed my steps.  They work for <em>me</em> and they <em>may not </em>work for <em>you</em>!</p>
<p>That said, here are the steps:</p>
<ol>
<li>Add  <code>innodb_file_per_table </code>in your my.cnf file under [mysqld] section</li>
<li>run following commands at the prompt.  Your path to binaries might be different.</li>
<p><code>#note:  following assumes you are logged in as root<br />
mkdir -p /temp  #temp dir to save our sql dump<br />
#lets make a backup of current database. -p is used if there is pw set<br />
/usr/local/mysql/bin/mysqldump -R -q -p --all-databases &gt; /temp/all.sql<br />
#stop mysql so we can remove all the files in the dir<br />
/etc/init.d/mysql stop<br />
rm -fr /usr/local/mysql/var/* #remove all the files<br />
/usr/local/mysql/bin/mysql_install_db  #install default dbs<br />
#change ownership so mysql user can read/write to/from files<br />
chown -R mysql.mysql /usr/local/mysql/var/<br />
#start mysql so we can import our dump<br />
/etc/init.d/mysql start<br />
#note there is no -p since defaults don't have mysql pw set<br />
/usr/local/mysql/bin/mysql &lt; /temp/all.sql<br />
/etc/init.d/mysql restart</code></ol>
<p>This should be all you need to do.  At this point when you remove a database, it will delete the directory of the db and all the data contained within which in turn will give you your disk space back.</p>
<p>REMEMBER:  <strong>Backup your data</strong> and be smart about using code found on internet.  If you don&#8217;t know what you are doing, hire a consultant who does.</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>MySQL database backup file compression:  gzip vs bzip2</title>
		<link>http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/</link>
		<comments>http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/#comments</comments>
		<pubDate>Tue, 20 Mar 2007 01:12:29 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[uh...]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/</guid>
		<description><![CDATA[In one of my previous posts: MySQL backups, I talked about using a script for automating backups.  I show that we can use gzip to compress backup file to compress and save.  Since then, our backup file has been growing meg or two a day which is causing our backup files to get [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my previous posts: <a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL Backups">MySQL backups</a>, I talked about using a script for automating backups.  I show that we can use gzip to compress backup file to compress and save.  Since then, our backup file has been growing meg or two a day which is causing our backup files to get bigger and bigger every day.  We keep hourly backups for a week so you can imagine space usage is quite high.</p>
<p>I went and did few tests to see if its beneficial for us to use Bzip2 instead of gzip.  I could&#8217;ve tried 7z also but that is not something installed on most linux machines I work on and I didn&#8217;t want use a solution which will require me to add more software.  Here are the results:</p>
<p>Original sql file size: 584M<br />
Using gzip: 166M<br />
Time spent on compressing 1 minute 25 secs<br />
Using bzip2:  125M<br />
Time spent on compressing 1 minute 50 secs</p>
<p>As we can see that it takes longer to compress but file size is much smaller (adds up fast for multiple backups).  As our database grows bigger and bigger, the size difference will matter quite a bit.  Since we also ftp the file off the server to onsite/offsite location hourly as well.</p>
<p>Does anybody know of any backup techniques which we can use for free and we can do incrementals with? comments are always welcome.  To learn more about gzip or bzip2, see <a href="http://www.lamp-tips.com/man-pages/gzip/" title="man gzip - man page for gzip" target="_blank">man gzip</a> or <a href="http://www.lamp-tips.com/man-pages/bzip2/" title="man bzip2 - man page for bzip2" target="_blank">man bzip2</a> respectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>MySQL backups using mysqldump</title>
		<link>http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/</link>
		<comments>http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 00:03:28 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/</guid>
		<description><![CDATA[MySQL backups are essential to running a site with MySQL backend.  Generally you can get away with doing nightly backups but on our site, due to couple issues we had in past, we are forced to do hourly backups of our db.
Intially I was doing backup by using: mysqldump dbname &#62; weekdayHour.dbname.sql  hourly. [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL backups are essential to running a site with MySQL backend.  Generally you can get away with doing nightly backups but on our site, due to couple issues we had in past, we are forced to do hourly backups of our db.</p>
<p>Intially I was doing backup by using: <em>mysqldump dbname &gt; weekdayHour.dbname.sql</em>  hourly.  This allowed us to have week worth of backups done every hour and auto overwriting old backups.  Eventually we added stored procedures and triggers to the mix and all of the sudden this dump wasn&#8217;t getting all the stored procedures and triggers.  So we started using mysqldump with -R parameter which in man states:</p>
<blockquote><p>Dump stored routines (functions and procedures) from the dumped databases.</p></blockquote>
<p>Recently when we started to see more and more traffic, we noticed that our server was under heavy load on the hour.  Ofcourse we quickly found it was due to mysqldump running on the hour which was causing the lag.  Eventually we had enough traffic on the site where this was causing connection problems with mysql.  So I went through man mysqldump again to find solution.  And thanks to those smart people in mysqldump dev team, there I found couple more parameters to make this backup process little less painful.  At this point we are using:  <em>mysqldump -R  -q &#8211;single-transaction &gt; weekdayHour.dbname.sql</em>  This seems to have decreased the load on the server and we haven&#8217;t got errors connecting to mysql.  Since we use innodb tables in this particular db, we could use <em>single-transaction</em> parameter.  Here is what our friendly man mysqldump has to say about these two parameters:</p>
<blockquote><p> -q    &#8230;This option is useful for dumping large tables. It forces mysqldump to retrieve rows for a table from the   server a row at a time rather than retrieving the entire row set and buffering it in memory before writing   it out&#8230;</p>
<p>&#8211;single-transaction   &#8230;This option issues a BEGIN SQL statement before dumping data from the server. It is useful only with transactional tables such as InnoDB and BDB, because then it dumps the consistent state of the database at the time when BEGIN was issued without blocking any applications&#8230;</p></blockquote>
<p>If you are thinking about using these two parameters, please spend couple minutes reading through man mysqldump and look at other notes which might pertain to your setup.</p>
<p>One last but very important thing we do after our backups are run is to move the new backup files off the server just in case server dies.  I achieved this by using ncftp package which includes ncftpput command line utility.  With ncftp, you can store ip/login/pw in a file and tell ncftp to use that for login information.  Lets look at the script as a whole:</p>
<p>NOTE:  comments in this script is for information purposes only.  You can remove them if you like</p>
<p><code>#!/bin/bash<br />
#<br />
#<a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/">http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/</a><br />
#<br />
DATE=`date '+%u%H'` # this sets up weekly rotation of backup files<br />
BACKUP_DIR="/admin/backups/domain.com/" # this dir will be created if it doesn't exist<br />
HOST=`hostname` #you may want to hard code this if you hostname returns wrong information<br />
mkdir ${BACKUP_DIR}mysql/ -p<br />
/usr/local/mysql/bin/mysqldump -R  -q --single-transaction --databases dbname1 dbname2 -ppassword &gt; ${BACKUP_DIR}mysql/$HOST$DATE.sql<br />
rm ${BACKUP_DIR}mysql/$HOST$DATE.sql.gz &gt; /dev/null 2&gt;&amp;1<br />
gzip -9 ${BACKUP_DIR}mysql/$HOST$DATE.sql &gt; /dev/null 2&gt;&amp;1<br />
/usr/bin/ncftpput -R -f ${BACKUP_DIR}hostinfo / ${BACKUP_DIR}mysql/$HOST$DATE.sql.gz</code></p>
<p>This is what your hostinfo file should contain (just make sure you edit it and put your own server ip, username, and password):<br />
<code>host 123.123.123.123<br />
user loginname<br />
pass loginpassword</code></p>
<p>To read more about mysqldump, see <a href="http://www.lamp-tips.com/man-pages/mysqldump/" title="man mysqldump - man page for mysqldump" target="_blank">man mysqldump</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
