2014-08-11 23:53:33 +02:00
|
|
|
mysql_utils for Debian or Other OS
|
2014-05-27 11:30:16 +02:00
|
|
|
=======================================
|
2013-06-12 00:10:39 +02:00
|
|
|
|
2015-10-08 02:09:48 +02:00
|
|
|
Russian documentation: http://docs.mirocow.com/doku.php?id=mysql:mysql_utils
|
|
|
|
|
2013-06-12 00:10:39 +02:00
|
|
|
Backup and Restore data from MySql tables
|
2013-11-23 18:17:53 +01:00
|
|
|
|
2014-04-21 14:44:31 +02:00
|
|
|
Install
|
|
|
|
======
|
|
|
|
|
|
|
|
cd ~
|
|
|
|
git clone https://github.com/Mirocow/mysql_utils.git
|
|
|
|
cd mysql_utils
|
|
|
|
|
2014-05-23 10:35:42 +02:00
|
|
|
Backup all databases
|
2014-04-21 14:44:31 +02:00
|
|
|
======
|
|
|
|
|
|
|
|
cd ~
|
|
|
|
cd mysql_utils
|
|
|
|
bash backup.sh
|
|
|
|
|
2015-12-24 13:14:56 +01:00
|
|
|
Backup selected database
|
|
|
|
======
|
|
|
|
|
|
|
|
cd ~
|
|
|
|
cd mysql_utils
|
|
|
|
bash backup_db.sh <[database-name]>
|
|
|
|
|
2014-05-23 10:33:45 +02:00
|
|
|
Restore for selected date
|
2014-04-21 14:44:31 +02:00
|
|
|
=======
|
|
|
|
|
2014-05-23 10:33:45 +02:00
|
|
|
cd /var/backups/mysql/[some date]
|
2014-04-21 14:44:31 +02:00
|
|
|
bash ~/mysql_utils/restore.sh
|
|
|
|
|
2015-05-12 17:06:02 +02:00
|
|
|
Restore selected DB
|
2014-05-23 10:32:45 +02:00
|
|
|
=======
|
|
|
|
|
|
|
|
cd /var/backups/mysql/[some date]/[some db name]
|
2015-05-12 17:06:02 +02:00
|
|
|
bash ~/mysql_utils/restore_db.sh
|
2014-05-23 10:32:45 +02:00
|
|
|
|
2013-11-23 18:17:53 +01:00
|
|
|
Automation backup with Cron
|
|
|
|
===========================
|
|
|
|
|
2014-04-21 14:16:04 +02:00
|
|
|
nano /etc/default/db_backup
|
|
|
|
|
|
|
|
START=yes
|
|
|
|
|
2014-08-11 23:50:59 +02:00
|
|
|
nano /etc/cron.daily/db_backup
|
2013-11-23 18:17:53 +01:00
|
|
|
|
2014-08-11 23:50:59 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. /etc/default/db_backup
|
|
|
|
|
|
|
|
if [ "$START" = "yes" ]; then
|
|
|
|
logger "Start databases backup system..."
|
2015-10-08 02:12:00 +02:00
|
|
|
/bin/bash /root/scripts/mysql_utils/backup.sh --e="some_exclude_database some_else_db"
|
2014-08-11 23:50:59 +02:00
|
|
|
fi
|
2014-04-21 14:48:26 +02:00
|
|
|
|
|
|
|
Check work
|
|
|
|
==========
|
|
|
|
|
2014-05-23 10:32:45 +02:00
|
|
|
# tail -f /var/log/syslog
|
|
|
|
May 23 12:25:34 db1 logger: BACKUP: ** Dump tecdoc.2013.ALI_COORD
|
|
|
|
May 23 12:25:35 db1 logger: BACKUP: ** set perm on tecdoc.2013/AL
|
|
|
|
May 23 12:25:35 db1 logger: BACKUP: ** bzip2 tecdoc.2013/ALI_COOR
|
|
|
|
May 23 12:25:35 db1 logger: BACKUP: ** Dump tecdoc.2013.ARTICLES
|
|
|
|
May 23 12:25:43 db1 logger: BACKUP: ** set perm on tecdoc.2013/AR
|
|
|
|
May 23 12:25:43 db1 logger: BACKUP: ** bzip2 tecdoc.2013/ARTICLES
|
|
|
|
May 23 12:25:43 db1 logger: BACKUP: ** Dump tecdoc.2013.ARTICLES_
|
|
|
|
May 23 12:25:43 db1 logger: BACKUP: ** set perm on tecdoc.2013/AR
|
|
|
|
May 23 12:25:43 db1 logger: BACKUP: ** bzip2 tecdoc.2013/ARTICLES
|
|
|
|
May 23 12:25:43 db1 logger: BACKUP: ** Dump tecdoc.2013.ARTICLE_C
|
|
|
|
|
2014-05-27 11:30:16 +02:00
|
|
|
Tested on
|
|
|
|
==========
|
|
|
|
|
|
|
|
Debiad
|
|
|
|
FreeBsd
|
|
|
|
Ubuntu
|
2015-10-08 02:12:00 +02:00
|
|
|
|
|
|
|
Help
|
|
|
|
===========
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
# bash backup.sh --help
|
|
|
|
usage: backup.sh options
|
|
|
|
|
|
|
|
This script buckup all databases.
|
|
|
|
|
|
|
|
Usage: backup.sh <[options]>
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-e= | --exclude= Exclude databases
|
|
|
|
--exclude-tables= Exclude tables
|
|
|
|
-c= | --compress= Compress with gzip or bzip2
|
|
|
|
-v | --verbose Add verbose into output
|
|
|
|
-l | --lifetime= Lifetime for dump files
|
|
|
|
--config= Config file of Debian format
|
|
|
|
--dir= Backup directory
|
|
|
|
-h | --help This text
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
backup.sh --verbose --compress=
|
|
|
|
backup.sh --verbose --compress=zgip
|
|
|
|
backup.sh --verbose --compress=bzip2
|
|
|
|
backup.sh --verbose --compress= --exclude="mysql"
|
|
|
|
backup.sh --verbose --compress= --exclude="mysql" --lifetime="3 day ago"
|
|
|
|
backup.sh --verbose --config="/etc/mysql/debian.cnf" --exclude="mysql" --lifetime="1 day ago"
|
|
|
|
backup.sh --verbose --dir="/var/backups/mysql" --config="/etc/mysql/debian.cnf" --exclude="mysql" --lifetime="1 day ago"
|
|
|
|
backup.sh --verbose --dir="/home/backups/mysql" --exclude="mysql" --lifetime="1 day ago"
|
|
|
|
backup.sh --verbose --dir="/home/backups/mysql" --exclude="mysql" --exclude-tables="tbl_template" --lifetime="1 day ago"
|
|
|
|
```
|