Проект

Общее

Профиль

MySQL backup » История » Версия 3

Dmitry Chernyak, 23.11.2011 16:14

1 1 Dmitry Chernyak
h1. MySQL backup
2 1 Dmitry Chernyak
3 1 Dmitry Chernyak
We're using the backup mysql via shutdown/startup.
4 1 Dmitry Chernyak
There are some disadvantages, but, in common for many sites this will be a good choce because
5 1 Dmitry Chernyak
* This is much faster than the dump in the backup.
6 1 Dmitry Chernyak
* This is very much faster than the restoring from the dump.
7 1 Dmitry Chernyak
* This allowing to not differ between MyISAM and InnoDB.
8 1 Dmitry Chernyak
* This allowing to save traffic via duplicity's block-based incremental alogrithms (implemented via librsync).
9 1 Dmitry Chernyak
10 1 Dmitry Chernyak
To do the backup you have to place the following files in your mysql backup job's profile:
11 1 Dmitry Chernyak
File "pre"
12 1 Dmitry Chernyak
<pre>
13 1 Dmitry Chernyak
if [ `ps ax|grep mysqld|grep -v grep|wc -l` -eq 0 ]; then
14 1 Dmitry Chernyak
  mysql_stopped=yes
15 2 Dmitry Chernyak
  echo "Warning: MySQL is not running."
16 1 Dmitry Chernyak
else
17 1 Dmitry Chernyak
  /etc/init.d/mysql stop
18 1 Dmitry Chernyak
  sleep 5
19 1 Dmitry Chernyak
  if [ `ps ax|grep mysqld|grep -v grep|wc -l` -gt 0 ]; then
20 3 Dmitry Chernyak
    echo "Error: MySQL is not stopped. Skiping backup"
21 1 Dmitry Chernyak
    exit 1
22 1 Dmitry Chernyak
  fi
23 1 Dmitry Chernyak
fi
24 1 Dmitry Chernyak
</pre>
25 1 Dmitry Chernyak
26 1 Dmitry Chernyak
File "post"
27 1 Dmitry Chernyak
<pre>
28 1 Dmitry Chernyak
if [ -z "$mysql_stopped" ]; then
29 1 Dmitry Chernyak
  /etc/init.d/mysql start
30 1 Dmitry Chernyak
  sleep 5
31 1 Dmitry Chernyak
  if [ `ps ax|grep mysqld|grep -v grep|wc -l` -eq 0 ]; then
32 1 Dmitry Chernyak
    echo "Error: MySQL is not restarted properly. Take care."
33 1 Dmitry Chernyak
    exit 1
34 1 Dmitry Chernyak
  fi
35 1 Dmitry Chernyak
fi
36 1 Dmitry Chernyak
</pre>