mysql backup script #1

This commit is contained in:
CaptainArk 2016-03-13 18:10:10 +01:00
parent 7ad215ab23
commit 19453bcc9a
6 changed files with 78 additions and 2 deletions

View File

@ -88,6 +88,8 @@
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<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>
<dd><a href="https://captainark.net/postfix-admin.html">Postfix Admin</a></dd>
<dt>Tue 02 February 2016</dt>

View File

@ -87,6 +87,18 @@
<div class="container">
<div class="row">
<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">
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
<h2 class="post-title">

View File

@ -90,7 +90,7 @@
<div class="post-preview">
<a href="https://captainark.net/author/antoine-joubert.html" rel="bookmark">
<h2 class="post-title">
Antoine Joubert (6)
Antoine Joubert (7)
</h2>
</a>
</div>

View File

@ -87,6 +87,18 @@
<div class="container">
<div class="row">
<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">
<a href="https://captainark.net/flexget-init-script.html" rel="bookmark" title="Permalink to Flexget init script">
<h2 class="post-title">

View File

@ -90,6 +90,18 @@
<div class="container">
<div class="row">
<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">
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
<h2 class="post-title">

View File

@ -1,5 +1,43 @@
<?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">&lt;p&gt;As I explained in &lt;a href="https://www.captainark.net/setting-up-a-mail-server.html"&gt;this previous tutorial&lt;/a&gt;, I've been running my own mail server without any issue for some time now.&lt;/p&gt;
<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">&lt;p&gt;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.&lt;/p&gt;
&lt;h2&gt;The script&lt;/h2&gt;
&lt;p&gt;For the script to work, you'll need to edit a few variable to match your configuration.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;BACKUPDIR&lt;/code&gt; is the path of the directory where you want your backups to be stored.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BACKUPUSR&lt;/code&gt; is the user that will connect to MySQL to dump the databases. It should have access to all you databases without needing a password.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;EXCLUDELIST&lt;/code&gt; is a list of databases that should not be backed-up. Leaving it as is is probably fine.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="ch"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nv"&gt;BACKUPDIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;/home/user/backup&amp;quot;&lt;/span&gt;
&lt;span class="nv"&gt;BACKUPUSR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;user&amp;quot;&lt;/span&gt;
&lt;span class="nv"&gt;EXCLUDELIST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;^Databases&lt;/span&gt;$&lt;span class="s2"&gt;|^information_schema&lt;/span&gt;$&lt;span class="s2"&gt;|^mysql&lt;/span&gt;$&lt;span class="s2"&gt;|^performance_schema&lt;/span&gt;$&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
sqlbk&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; each in &lt;span class="k"&gt;$(&lt;/span&gt;mysqlshow &lt;span class="p"&gt;|&lt;/span&gt; awk &lt;span class="s1"&gt;&amp;#39;/[[:alnum:]]/{print $2}&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$each&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ &lt;span class="nv"&gt;$EXCLUDELIST&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
mysqldump &lt;span class="nv"&gt;$each&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; bzip2 &amp;gt; &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;BACKUPDIR&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;/&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;each&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;.sql.bz2
chown &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;BACKUPUSR&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;: &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;BACKUPDIR&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;/&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;each&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;.sql.bz2 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; chmod &lt;span class="m"&gt;600&lt;/span&gt; &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;BACKUPDIR&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;/&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;each&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;.sql.bz2
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;[[&lt;/span&gt; -e /usr/bin/mysql &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; sqlbk
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I personnaly have this script running once a week, in my user's personnal crontab (editable using the &lt;code&gt;crontab -e&lt;/code&gt; command) :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;## WEEKLY DATABASE BACKUP
@weekly /home/user/bin/backupdb
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;You've probably noticed that the script erases the previous backup when a new one is made.&lt;/p&gt;
&lt;p&gt;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 &lt;a href="http://rsnapshot.org/"&gt;Rsnapshot&lt;/a&gt;. I'll probably write an article on the subject in the future.&lt;/p&gt;
&lt;p&gt;As usual, feedback is always appreciated !&lt;/p&gt;</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">&lt;p&gt;As I explained in &lt;a href="https://www.captainark.net/setting-up-a-mail-server.html"&gt;this previous tutorial&lt;/a&gt;, I've been running my own mail server without any issue for some time now.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;After a bit a googling, I've settled on &lt;a href="http://postfixadmin.sourceforge.net/"&gt;Postfix Admin&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;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 &lt;a href="https://github.com/postfixadmin/postfixadmin"&gt;Github repo&lt;/a&gt;.&lt;/p&gt;