<?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>Admon Home &#187; replication</title>
	<atom:link href="http://www.admon.org/tag/replication/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.admon.org</link>
	<description>Linux System Administration</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:24:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Purge MySQL Binary Logs periodically</title>
		<link>http://www.admon.org/purge-mysql-binary-logs-periodically/</link>
		<comments>http://www.admon.org/purge-mysql-binary-logs-periodically/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 12:22:45 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[bin-log]]></category>
		<category><![CDATA[logfiles]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=553</guid>
		<description><![CDATA[If you have binary logging enabled on your MySQL server (i.e. the log-bin parameter is set in the config file), then you may notice a bulk of large files in the MySQL data directory over time. Generally you only need to enable this binary logging if your server is acting as a relication master or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg"><img class="alignleft size-full wp-image-758" title="mysql" src="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg" alt="MySQL database" width="150" height="150" /></a>If you have binary logging enabled on your MySQL server (i.e. the <a href="http://dev.mysql.com/doc/refman/5.0/en/binary-log.html">log-bin parameter</a> is set in the config file), then you may notice a bulk of large files in the MySQL data directory over time. Generally you only need to enable this binary logging if your server is acting as a relication master or if you need the ability to do point in time recovery from your latest backup.<span id="more-553"></span></p>
<p>NOTE: On a <a href="http://www.howtoforge.com/mysql_database_replication">MySQL replication</a> environment, users must be careful in deleting binary logs. If slaves are lagging behind the server SOME days, the binary log purge might cause replication to fail. Make sure the logs file are not in use before removing them!</p>
<p>In any case here are some useful examples for purging binary log files easiliy. We&#8217;ll show you two quick ways on deleting the expired bin-log files.</p>
<p>As the purge work here is issued by mysql itself, please make sure you have MySQL-4.1 and later version installed. For version 4.0 and 3.xx, it does not support the following feathers.</p>
<p>1, <strong>Delete MySQL bin-log files by PURGE statement</strong></p>
<p>For example, if you need to delete all binary logs older than 7 days, you just need to run this sql:</p>
<pre>mysql&gt; PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);</pre>
<p>To purge all logs before a specific date:</p>
<pre>mysql&gt; PURGE MASTER LOGS BEFORE '2010-03-01 00:00:00';</pre>
<p>To purge logs automatically (every Monday at 3am) you could use a cron job like this:</p>
<pre>0 3 * * mon mysql -uroot -e 'PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY)'</pre>
<p>2, <strong>Remove bin-log by <a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html">the variable expire_log_days</a></strong></p>
<p>An alternative option is to set &#8220;expire_log_days&#8221; as MySQL server parameter. The default values for expire_log_days is not to purge logs. You can either set it in MySQL&#8217;s configuration file or in a command terminal like below:</p>
<pre>mysql&gt; SET GLOBAL expire_logs_days = 7;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; show variables like 'expire_%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days |  7    |
+------------------+-------+
1 row in set (0.00 sec)</pre>
<p>When this vavirable takes effect, the log files will be removed automatically on a weekly basis.<br />
For any issues, don&#8217;t forget to raise a thread at our <a href="http://forum.admon.org/databases/">database support forum</a> here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/purge-mysql-binary-logs-periodically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips for Rebuilding MySQL Replication</title>
		<link>http://www.admon.org/tips-for-rebuilding-mysql-replication/</link>
		<comments>http://www.admon.org/tips-for-rebuilding-mysql-replication/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 04:42:53 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=462</guid>
		<description><![CDATA[Let&#8217;s keep this post smart. It&#8217;s intended to help you rebuild a crashed MySQL replication. We assume that bin-log has been enabled at the master side. Basically what you need to do is to retrival a snapshot of your master database. It covers three types of information, a snapshot of your current mysql database, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg"><img class="alignleft size-full wp-image-758" title="mysql" src="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg" alt="MySQL database" width="150" height="150" /></a>Let&#8217;s keep this post smart. It&#8217;s intended to help you rebuild a crashed MySQL replication. We assume that bin-log has been enabled at the master side.</p>
<p>Basically what you need to do is to retrival a snapshot of your master database. It covers three types of information, a snapshot of your current mysql database, and master log file name and its running position when this snapshot created.<span id="more-462"></span></p>
<p>You can achieve these information on a running DB like this:</p>
<p>Firstly, frozen your database, in order to disable any writes/updates on the databases. It affects your service for sure. Run two sql queries on a terminal:</p>
<pre>mysql&gt; FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.53 sec)

mysql&gt; SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| binlog-db.000004 |  88689   |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.01 sec)
</pre>
<p>Keep this session open.  Note that when this session closes, READ LOCK will vanish, and your database will keep changing again.</p>
<p>Then open another terminal to create a copy of your current database files. There are three common ways to do that depending on your system environment. Either of these methods is okay.</p>
<p>1, Use mysqldump to copy all the data.</p>
<p>The disadvantage for mysqldump is that it uses very long time for dumpping large databases. It&#8217;s really unacceptable on productive servers.</p>
<pre>shell$ mysqldump --database db1 db2 &gt; fullbackup-timestamp.sql</pre>
<p>2, Use a LVM snapshot</p>
<p>It only takes some seconds to create a <a href="http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html">LVM snapshot</a>. When your snapshot created, you can copy the snapshot to the slave server.<br />
As all the database files are exactly the same as master DB, you need to make sure the configuration files are similar as well.</p>
<p>3, Use XFS&#8217; frozen feature to do that</p>
<pre>SYSTEM xfs_freeze -f /var/lib/mysql;
SYSTEM YOUR_SCRIPT_TO_CREATE_SNAPSHOT.sh;
SYSTEM xfs_freeze -u /var/lib/mysql;</pre>
<p>After the snapshot createed, you either leave the first session, or submit this query directly:</p>
<pre>mysql&gt; UNLOCK TABLES;</pre>
<p>Finally you need to restore these databases from mysql dump file or the snapshot at slave side. When recovering a large database, time make lots of sense. it might take you one or more days to finish a recovery.<br />
To speed up a mysql recovery, there&#8217;re always some valuable advises from wise man (The wise man here is &#8230; my friend). for example you can disable binlog when importing large sql files.</p>
<pre>mysql&gt; SET SQL_LOG_BIN=0;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; SOURCE /PATH/TO/MYSQL-BACKUP.SQL</pre>
<p>When the files are importing, you need to make sure there are enough disk space avaiable, otherwise, it would crashed again. After importing all data files at slave side,  you need to tell the slave at which point it should read binlog from master:</p>
<pre>mysql&gt; SLAVE STOP;

mysql&gt; SLAVE RESET;

mysql&gt; CHANGE MASTER TO MASTER_HOST='pub.admon.org',MASTER_LOG_FILE='binlog-db.000004',MASTER_LOG_POS=88689;

myql&gt; SLAVE START;</pre>
<p>If all your recovery work is a remote operation, <a href="http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/">using Screen</a> is highly suggested.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/tips-for-rebuilding-mysql-replication/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Repair MySQL Replication by SQL_SLAVE_SKIP_COUNTER</title>
		<link>http://www.admon.org/repair-mysql-replication-by-sql_slave_skip_counter/</link>
		<comments>http://www.admon.org/repair-mysql-replication-by-sql_slave_skip_counter/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 11:17:47 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://blog.admon.org/?p=169</guid>
		<description><![CDATA[If you set up MySQL replication, you probably have ever faced this problem. there are invalid MySQL queries which cause the replication not to work anymore. Here I&#8217;ll explain how you can repair the replication on MySQL slave without rebuilding the whole repication environment. There are two steps here: 1 &#8211; Identifying The Problem To [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg"><img class="alignleft size-full wp-image-758" title="mysql" src="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg" alt="MySQL database" width="140" height="140" /></a>If you set up MySQL replication, you probably have ever faced this problem. there are invalid MySQL queries which cause the replication not to work anymore. Here I&#8217;ll explain how you can repair the replication on MySQL slave without <a href="http://www.howtoforge.com/mysql_database_replication">rebuilding the whole repication environment</a>. There are two steps here:<span id="more-169"></span></p>
<p><strong>1 &#8211; Identifying The Problem</strong></p>
<p>To find out whether replication is working or not, and check mysql logs<br />
to make sure what caused it to stop. On Debian, MySQL logs to<br />
/var/log/syslog:</p>
<pre>admon:/home/admin# grep mysql /var/log/syslog
server1:/home/admin# grep mysql /var/log/syslog
Jun 29 09:16:08 http2 mysqld[14380]: 080629 9:16:08 [ERROR] Slave: Error
'Table 'mydb.taggregate_temp_1212347876' doesn't exist' on query. Default database: 'mydb'. Query: 'UPDATE thread AS thread,taggregate_temp_1212347876 AS aggregate
Jun 29 09:16:08 http2 mysqld[14380]: ^ISET thread.views = thread.views + aggregate.views
Jun 29 09:16:08 http2 mysqld[14380]: ^IWHERE thread.threadid = aggregate.threadid', Error_code: 1146
Jun 29 09:16:08 http2 mysqld[14380]: 080629 9:56:08 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.001079' position 203015142
</pre>
<p>Now, you can see the query that caused the error, and the stop position. To determine the exact query:</p>
<pre>mysql&gt; SHOW SLAVE STATUSG
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
....
Last_Errno: 1146
Last_Error: Error 'Table 'mydb.taggregate_temp_1212347876' doesn't exist' on query. Default database: 'mydb'.
Query: 'UPDATE thread AS thread,taggregate_temp_1212347876 AS aggregate
SET thread.views = thread.views + aggregate.views
WHERE thread.threadid = aggregate.threadid'
Skip_Counter: 0
......
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
1 row in set (0.00 sec)
mysql&gt;</pre>
<p>New we are prepare to fix this issue.<br />
<strong>2 &#8211; Repairing The Replication</strong><br />
we need to stop the slave first, by running:</p>
<pre>mysql&gt; STOP SLAVE;</pre>
<p>To Fix the issue is quite easy. We tell the slave to simply skip the invalid SQL query here:</p>
<pre>mysql&gt; SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;</pre>
<p>This tells the slave to skip one query (which is the invalid one that<br />
caused the replication to stop). If you wanna skip two queries, you&#8217;d<br />
use SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 2; instead and so on.</p>
<p>Now the issue has been fixed, we can start the slave again by running:</p>
<pre>mysql&gt; START SLAVE;</pre>
<p>and then,check if replication is working smoothly again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/repair-mysql-replication-by-sql_slave_skip_counter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

