mysql backup script #1
This commit is contained in:
parent
7ad215ab23
commit
19453bcc9a
@ -88,6 +88,8 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||||
<dl>
|
<dl>
|
||||||
|
<dt>Sun 13 March 2016</dt>
|
||||||
|
<dd><a href="https://captainark.net/mysql-backup-script.html">MySQL backup script</a></dd>
|
||||||
<dt>Sun 06 March 2016</dt>
|
<dt>Sun 06 March 2016</dt>
|
||||||
<dd><a href="https://captainark.net/postfix-admin.html">Postfix Admin</a></dd>
|
<dd><a href="https://captainark.net/postfix-admin.html">Postfix Admin</a></dd>
|
||||||
<dt>Tue 02 February 2016</dt>
|
<dt>Tue 02 February 2016</dt>
|
||||||
|
@ -87,6 +87,18 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||||
|
<div class="post-preview">
|
||||||
|
<a href="https://captainark.net/mysql-backup-script.html" rel="bookmark" title="Permalink to MySQL backup script">
|
||||||
|
<h2 class="post-title">
|
||||||
|
MySQL backup script
|
||||||
|
</h2>
|
||||||
|
</a>
|
||||||
|
<p>I wrote a MySQL database backup script a while back. I known they are more than enough of them already floating around the internet, ...
|
||||||
|
<p class="post-meta">Posted by
|
||||||
|
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
|
||||||
|
on Sun 13 March 2016
|
||||||
|
</p>
|
||||||
|
<p>There are <a href="https://captainark.net/mysql-backup-script.html#disqus_thread">comments</a>.</p> </div>
|
||||||
<div class="post-preview">
|
<div class="post-preview">
|
||||||
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
|
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
|
||||||
<h2 class="post-title">
|
<h2 class="post-title">
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
<div class="post-preview">
|
<div class="post-preview">
|
||||||
<a href="https://captainark.net/author/antoine-joubert.html" rel="bookmark">
|
<a href="https://captainark.net/author/antoine-joubert.html" rel="bookmark">
|
||||||
<h2 class="post-title">
|
<h2 class="post-title">
|
||||||
Antoine Joubert (6)
|
Antoine Joubert (7)
|
||||||
</h2>
|
</h2>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -87,6 +87,18 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||||
|
<div class="post-preview">
|
||||||
|
<a href="https://captainark.net/mysql-backup-script.html" rel="bookmark" title="Permalink to MySQL backup script">
|
||||||
|
<h2 class="post-title">
|
||||||
|
MySQL backup script
|
||||||
|
</h2>
|
||||||
|
</a>
|
||||||
|
<p>I wrote a MySQL database backup script a while back. I known they are more than enough of them already floating around the internet, ...
|
||||||
|
<p class="post-meta">Posted by
|
||||||
|
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
|
||||||
|
on Sun 13 March 2016
|
||||||
|
</p>
|
||||||
|
<p>There are <a href="https://captainark.net/mysql-backup-script.html#disqus_thread">comments</a>.</p> </div>
|
||||||
<div class="post-preview">
|
<div class="post-preview">
|
||||||
<a href="https://captainark.net/flexget-init-script.html" rel="bookmark" title="Permalink to Flexget init script">
|
<a href="https://captainark.net/flexget-init-script.html" rel="bookmark" title="Permalink to Flexget init script">
|
||||||
<h2 class="post-title">
|
<h2 class="post-title">
|
||||||
|
@ -90,6 +90,18 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||||
|
<div class="post-preview">
|
||||||
|
<a href="https://captainark.net/mysql-backup-script.html" rel="bookmark" title="Permalink to MySQL backup script">
|
||||||
|
<h2 class="post-title">
|
||||||
|
MySQL backup script
|
||||||
|
</h2>
|
||||||
|
</a>
|
||||||
|
<p>I wrote a MySQL database backup script a while back. I known they are more than enough of them already floating around the internet, ...
|
||||||
|
<p class="post-meta">Posted by
|
||||||
|
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
|
||||||
|
on Sun 13 March 2016
|
||||||
|
</p>
|
||||||
|
<p>There are <a href="https://captainark.net/mysql-backup-script.html#disqus_thread">comments</a>.</p> </div>
|
||||||
<div class="post-preview">
|
<div class="post-preview">
|
||||||
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
|
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
|
||||||
<h2 class="post-title">
|
<h2 class="post-title">
|
||||||
|
@ -1,5 +1,43 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom"><title>Sysadmining. All day. Every day.</title><link href="https://captainark.net/" rel="alternate"></link><link href="https://captainark.net/rss.xml" rel="self"></link><id>https://captainark.net/</id><updated>2016-03-06T00:00:00+01:00</updated><entry><title>Postfix Admin</title><link href="https://captainark.net/postfix-admin.html" rel="alternate"></link><updated>2016-03-06T00:00:00+01:00</updated><author><name>Antoine Joubert</name></author><id>tag:captainark.net,2016-03-06:postfix-admin.html</id><summary type="html"><p>As I explained in <a href="https://www.captainark.net/setting-up-a-mail-server.html">this previous tutorial</a>, I've been running my own mail server without any issue for some time now.</p>
|
<feed xmlns="http://www.w3.org/2005/Atom"><title>Sysadmining. All day. Every day.</title><link href="https://captainark.net/" rel="alternate"></link><link href="https://captainark.net/rss.xml" rel="self"></link><id>https://captainark.net/</id><updated>2016-03-13T00:00:00+01:00</updated><entry><title>MySQL backup script</title><link href="https://captainark.net/mysql-backup-script.html" rel="alternate"></link><updated>2016-03-13T00:00:00+01:00</updated><author><name>Antoine Joubert</name></author><id>tag:captainark.net,2016-03-13:mysql-backup-script.html</id><summary type="html"><p>I wrote a MySQL database backup script a while back. I known they are more than enough of them already floating around the internet, but hey, I figured I'd share it here anyway.</p>
|
||||||
|
<h2>The script</h2>
|
||||||
|
<p>For the script to work, you'll need to edit a few variable to match your configuration.</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>BACKUPDIR</code> is the path of the directory where you want your backups to be stored.</li>
|
||||||
|
<li><code>BACKUPUSR</code> is the user that will connect to MySQL to dump the databases. It should have access to all you databases without needing a password.</li>
|
||||||
|
<li><code>EXCLUDELIST</code> is a list of databases that should not be backed-up. Leaving it as is is probably fine.</li>
|
||||||
|
</ul>
|
||||||
|
<div class="highlight"><pre><span></span><span class="ch">#!/bin/bash</span>
|
||||||
|
|
||||||
|
<span class="nv">BACKUPDIR</span><span class="o">=</span><span class="s2">&quot;/home/user/backup&quot;</span>
|
||||||
|
<span class="nv">BACKUPUSR</span><span class="o">=</span><span class="s2">&quot;user&quot;</span>
|
||||||
|
<span class="nv">EXCLUDELIST</span><span class="o">=</span><span class="s2">&quot;^Databases</span>$<span class="s2">|^information_schema</span>$<span class="s2">|^mysql</span>$<span class="s2">|^performance_schema</span>$<span class="s2">&quot;</span>
|
||||||
|
|
||||||
|
sqlbk<span class="o">()</span> <span class="o">{</span>
|
||||||
|
<span class="k">for</span> each in <span class="k">$(</span>mysqlshow <span class="p">|</span> awk <span class="s1">&#39;/[[:alnum:]]/{print $2}&#39;</span><span class="k">)</span><span class="p">;</span> <span class="k">do</span>
|
||||||
|
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$each</span> <span class="o">=</span>~ <span class="nv">$EXCLUDELIST</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then</span>
|
||||||
|
<span class="nb">true</span>
|
||||||
|
<span class="k">else</span>
|
||||||
|
mysqldump <span class="nv">$each</span> <span class="p">|</span> bzip2 &gt; <span class="si">${</span><span class="nv">BACKUPDIR</span><span class="si">}</span>/<span class="si">${</span><span class="nv">each</span><span class="si">}</span>.sql.bz2
|
||||||
|
chown <span class="si">${</span><span class="nv">BACKUPUSR</span><span class="si">}</span>: <span class="si">${</span><span class="nv">BACKUPDIR</span><span class="si">}</span>/<span class="si">${</span><span class="nv">each</span><span class="si">}</span>.sql.bz2 <span class="o">&amp;&amp;</span> chmod <span class="m">600</span> <span class="si">${</span><span class="nv">BACKUPDIR</span><span class="si">}</span>/<span class="si">${</span><span class="nv">each</span><span class="si">}</span>.sql.bz2
|
||||||
|
<span class="k">fi</span>
|
||||||
|
<span class="k">done</span>
|
||||||
|
<span class="o">}</span>
|
||||||
|
|
||||||
|
<span class="o">[[</span> -e /usr/bin/mysql <span class="o">]]</span> <span class="o">&amp;&amp;</span> sqlbk
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
|
||||||
|
<p>I personnaly have this script running once a week, in my user's personnal crontab (editable using the <code>crontab -e</code> command) :</p>
|
||||||
|
<div class="highlight"><pre><span></span>## WEEKLY DATABASE BACKUP
|
||||||
|
@weekly /home/user/bin/backupdb
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
|
||||||
|
<h1>Conclusion</h1>
|
||||||
|
<p>You've probably noticed that the script erases the previous backup when a new one is made.</p>
|
||||||
|
<p>I don't need to keep multiple versions of the same database backup on my servers because they are all saved remotely on a daily basis using <a href="http://rsnapshot.org/">Rsnapshot</a>. I'll probably write an article on the subject in the future.</p>
|
||||||
|
<p>As usual, feedback is always appreciated !</p></summary></entry><entry><title>Postfix Admin</title><link href="https://captainark.net/postfix-admin.html" rel="alternate"></link><updated>2016-03-06T00:00:00+01:00</updated><author><name>Antoine Joubert</name></author><id>tag:captainark.net,2016-03-06:postfix-admin.html</id><summary type="html"><p>As I explained in <a href="https://www.captainark.net/setting-up-a-mail-server.html">this previous tutorial</a>, I've been running my own mail server without any issue for some time now.</p>
|
||||||
<p>However, every time I've wanted to add a domain, create a new mailbox or change a user's password, I've had to do it manually from a SQL shell. As fun as it may be, it does get old very fast, so I've decided to install a web frontend to manage this database.</p>
|
<p>However, every time I've wanted to add a domain, create a new mailbox or change a user's password, I've had to do it manually from a SQL shell. As fun as it may be, it does get old very fast, so I've decided to install a web frontend to manage this database.</p>
|
||||||
<p>After a bit a googling, I've settled on <a href="http://postfixadmin.sourceforge.net/">Postfix Admin</a>.</p>
|
<p>After a bit a googling, I've settled on <a href="http://postfixadmin.sourceforge.net/">Postfix Admin</a>.</p>
|
||||||
<p>The latest stable version of Postfix Admin was released in 2009. Version 3.0 has been in the works for some time now and the project can be cloned from their <a href="https://github.com/postfixadmin/postfixadmin">Github repo</a>.</p>
|
<p>The latest stable version of Postfix Admin was released in 2009. Version 3.0 has been in the works for some time now and the project can be cloned from their <a href="https://github.com/postfixadmin/postfixadmin">Github repo</a>.</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user