<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Backing up MySQL</title>
	<atom:link href="http://etbe.coker.com.au/2009/11/15/backing-up-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://etbe.coker.com.au/2009/11/15/backing-up-mysql/</link>
	<description>Linux, politics, and other interesting things</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:45:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: craig</title>
		<link>http://etbe.coker.com.au/2009/11/15/backing-up-mysql/comment-page-1/#comment-21728</link>
		<dc:creator>craig</dc:creator>
		<pubDate>Thu, 26 Nov 2009 20:15:04 +0000</pubDate>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=1417#comment-21728</guid>
		<description>Hi Russell,

here&#039;s the latest variation of my mysql backup script.  for each database, it dumps the schema (table &amp; index creation, etc) and data into separate files.  I&#039;ve found that it&#039;s extremely convenient to have the table creation commands separate from the data.

actually, it backups up two copies of the data.  one with extended inserts, one with complete inserts.  In the past, i&#039;ve had the occasional problem with restoring extended inserts - complete inserts are much slower but 100% reliable.

it dumps these to a temporary directory, and then uses rdiff-backup to make a revision-controlled backup to a standard location (/var/backups/mysql/$HOSTNAME).  this can then be rsynced to another (central) host.


feel free to scavenge ideas from the script, or adapt it your needs.

it assumes there is a ~/.my.cnf file to get the login details from.


#! /bin/bash

HOST=$(hostname -s)

BACKUPDIR=/var/backups/mysql/$HOST
TMPDIR=/tmp/mysql-backups/$HOST
mkdir -p $BACKUPDIR $TMPDIR

ARGS=&quot;--single-transaction --flush-logs --skip-opt --no-create-db --no-create-info&quot;

DATABASES=$( mysql -D mysql --skip-column-names -B -e &#039;show databases;&#039; &#124; egrep -v &#039;information_schema&#039; );

mysql -Bse &quot;SELECT CONCAT(&#039;SHOW GRANTS FOR \&#039;&#039;, user ,&#039;\&#039;@\&#039;&#039;, host, &#039;\&#039;;&#039;) FROM mysql.user&quot; &#124; mysql -Bs &#124; sed &#039;s/$/;/g&#039;  &gt; mysql-grants.txt

for i in $DATABASES ; do
    # &quot;create database&quot; lines, for easy cut-and-paste
    echo &quot;CREATE DATABASE $i;&quot; &gt;&gt; $TMPDIR/mysql-create-databases.txt

    echo -n &quot;backing up $i: schema...&quot;
    mysqldump $ARGS --no-data $i &gt; $TMPDIR/$i.schema.sql

    echo -n &quot;data...complete...&quot;
    mysqldump $ARGS --complete-insert $i &gt; $TMPDIR/$i.data.complete.sql

    echo -n &quot;extended...&quot;
    mysqldump $ARGS --extended-insert $i &gt; $TMPDIR/$i.data.extended.sql

    echo &quot;done.&quot;
done

RDIFF_ARGS=&quot;&quot;
rdiff-backup $RDIFF_ARGS $TMPDIR/ $BACKUPDIR/
</description>
		<content:encoded><![CDATA[<p>Hi Russell,</p>
<p>here&#8217;s the latest variation of my mysql backup script.  for each database, it dumps the schema (table &amp; index creation, etc) and data into separate files.  I&#8217;ve found that it&#8217;s extremely convenient to have the table creation commands separate from the data.</p>
<p>actually, it backups up two copies of the data.  one with extended inserts, one with complete inserts.  In the past, i&#8217;ve had the occasional problem with restoring extended inserts &#8211; complete inserts are much slower but 100% reliable.</p>
<p>it dumps these to a temporary directory, and then uses rdiff-backup to make a revision-controlled backup to a standard location (/var/backups/mysql/$HOSTNAME).  this can then be rsynced to another (central) host.</p>
<p>feel free to scavenge ideas from the script, or adapt it your needs.</p>
<p>it assumes there is a ~/.my.cnf file to get the login details from.</p>
<p>#! /bin/bash</p>
<p>HOST=$(hostname -s)</p>
<p>BACKUPDIR=/var/backups/mysql/$HOST<br />
TMPDIR=/tmp/mysql-backups/$HOST<br />
mkdir -p $BACKUPDIR $TMPDIR</p>
<p>ARGS=&#8221;&#8211;single-transaction &#8211;flush-logs &#8211;skip-opt &#8211;no-create-db &#8211;no-create-info&#8221;</p>
<p>DATABASES=$( mysql -D mysql &#8211;skip-column-names -B -e &#8216;show databases;&#8217; | egrep -v &#8216;information_schema&#8217; );</p>
<p>mysql -Bse &#8220;SELECT CONCAT(&#8216;SHOW GRANTS FOR \&#8221;, user ,&#8217;\'@\&#8221;, host, &#8216;\&#8217;;') FROM mysql.user&#8221; | mysql -Bs | sed &#8216;s/$/;/g&#8217;  &gt; mysql-grants.txt</p>
<p>for i in $DATABASES ; do<br />
    # &#8220;create database&#8221; lines, for easy cut-and-paste<br />
    echo &#8220;CREATE DATABASE $i;&#8221; &gt;&gt; $TMPDIR/mysql-create-databases.txt</p>
<p>    echo -n &#8220;backing up $i: schema&#8230;&#8221;<br />
    mysqldump $ARGS &#8211;no-data $i &gt; $TMPDIR/$i.schema.sql</p>
<p>    echo -n &#8220;data&#8230;complete&#8230;&#8221;<br />
    mysqldump $ARGS &#8211;complete-insert $i &gt; $TMPDIR/$i.data.complete.sql</p>
<p>    echo -n &#8220;extended&#8230;&#8221;<br />
    mysqldump $ARGS &#8211;extended-insert $i &gt; $TMPDIR/$i.data.extended.sql</p>
<p>    echo &#8220;done.&#8221;<br />
done</p>
<p>RDIFF_ARGS=&#8221;"<br />
rdiff-backup $RDIFF_ARGS $TMPDIR/ $BACKUPDIR/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Edmunds</title>
		<link>http://etbe.coker.com.au/2009/11/15/backing-up-mysql/comment-page-1/#comment-21451</link>
		<dc:creator>Keith Edmunds</dc:creator>
		<pubDate>Tue, 17 Nov 2009 20:35:22 +0000</pubDate>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=1417#comment-21451</guid>
		<description>Rather than:

    for n in db1 etc;do

try:

    for db in $(mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -Bse &#039;show databases&#039;);do

That way you don&#039;t have to remember to update the script when you create new databases.

Keith</description>
		<content:encoded><![CDATA[<p>Rather than:</p>
<p>    for n in db1 etc;do</p>
<p>try:</p>
<p>    for db in $(mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -Bse &#8216;show databases&#8217;);do</p>
<p>That way you don&#8217;t have to remember to update the script when you create new databases.</p>
<p>Keith</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florian</title>
		<link>http://etbe.coker.com.au/2009/11/15/backing-up-mysql/comment-page-1/#comment-21403</link>
		<dc:creator>Florian</dc:creator>
		<pubDate>Mon, 16 Nov 2009 00:03:55 +0000</pubDate>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=1417#comment-21403</guid>
		<description>I&#039;d advise to add --lock-all-tables to mysqldump or using mysqlhotcopy or mylvmbackup...</description>
		<content:encoded><![CDATA[<p>I&#8217;d advise to add &#8211;lock-all-tables to mysqldump or using mysqlhotcopy or mylvmbackup&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://etbe.coker.com.au/2009/11/15/backing-up-mysql/comment-page-1/#comment-21397</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sun, 15 Nov 2009 18:16:24 +0000</pubDate>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=1417#comment-21397</guid>
		<description>A useful trick we use for backing up our SQL (postgresql) database: dump it to a backup directory as a dated file, encrypted with GPG using both of our public keys, and then share that directory using anonymous rsync.  No need to secure rsync if it only copies secure data. :)</description>
		<content:encoded><![CDATA[<p>A useful trick we use for backing up our SQL (postgresql) database: dump it to a backup directory as a dated file, encrypted with GPG using both of our public keys, and then share that directory using anonymous rsync.  No need to secure rsync if it only copies secure data. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Fitzgerald</title>
		<link>http://etbe.coker.com.au/2009/11/15/backing-up-mysql/comment-page-1/#comment-21392</link>
		<dc:creator>Greg Fitzgerald</dc:creator>
		<pubDate>Sun, 15 Nov 2009 15:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=1417#comment-21392</guid>
		<description>I have created a backup user with limited resources on my sql server. I then backup databases on another machine. Mysql port is only open to this one ip address. Anyways posted my script here, http://gist.github.com/235274 ugly as sin currently, but some day I&#039;ll clean it up. Does get the job done great for my needs.</description>
		<content:encoded><![CDATA[<p>I have created a backup user with limited resources on my sql server. I then backup databases on another machine. Mysql port is only open to this one ip address. Anyways posted my script here, <a href="http://gist.github.com/235274" rel="nofollow">http://gist.github.com/235274</a> ugly as sin currently, but some day I&#8217;ll clean it up. Does get the job done great for my needs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://etbe.coker.com.au/2009/11/15/backing-up-mysql/comment-page-1/#comment-21390</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Sun, 15 Nov 2009 13:28:39 +0000</pubDate>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=1417#comment-21390</guid>
		<description>Ohh.. I also forgot to mention...  if you have system resource issues...

Try using both ionice and nice to drop the priority of the dumps.   I use that in conjunction with rsnapshot (mentioned above), to reduce the load on a server.   The combo works well.</description>
		<content:encoded><![CDATA[<p>Ohh.. I also forgot to mention&#8230;  if you have system resource issues&#8230;</p>
<p>Try using both ionice and nice to drop the priority of the dumps.   I use that in conjunction with rsnapshot (mentioned above), to reduce the load on a server.   The combo works well.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

