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