Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ MySQL combination Git achieve differential backups can be used in the production environment     - How to modify the Emacs Major Mode Shortcuts (Linux)

- JavaScript is implemented without new keywords constructor (Programming)

- Postmodern systems programming language (Programming)

- The method of Linux into the rescue mode (Linux)

- OpenSUSE installation on CentOS6 (GUI) (Linux)

- Linux environmental performance data acquisition system (Linux)

- Three kinds of implementation model of the Linux thread history (Programming)

- Ubuntu Linux use MAC binding against ARP attacks (Linux)

- To create a secure network firewall with iptables Under Linux (Linux)

- Linux garbled file delete method (Linux)

- LogStash log analysis display system (Linux)

- RCU lock in the evolution of the Linux kernel (Linux)

- MySQL Authorized a recovered (Database)

- Linux System Getting Started Learning: Debian download, installation and graphical interface (Linux)

- Linux operation and maintenance engineers face questions Intermediate (Linux)

- SSH service configuration to use a certificate login Linux server (Server)

- C ++ Supplements - References (Lvalue Reference, Rvalue Reference) (Linux)

- Apache Web Security Linux systems (Linux)

- Row-level security and application-level solutions for the new features of PostgreSQL9.5 (Database)

- Detailed iptables (Linux)

  MySQL combination Git achieve differential backups can be used in the production environment
  Add Date : 2018-11-21      
  Days sudden fantasy, contribute some strength for the LNMP camp. To share out the usual course of their work experiences and some tips. Today apes are most familiar with Mysql beginning bird house opening blog posts. Welcome apes Paizhuan reproduced.
Note: Bird house test and production environments for Ubuntu
Mysql is one development tool operation and maintenance procedures apes and monkeys are most concerned about, today to talk about the daily backup of Mysql in the house to see the birds.
Common Mysql backup in many ways this is not repeated here. Straight dry!
The shell script needs to be installed
We asked readers for mysql, git, ssh, shell have a certain understanding

The script function: Remote configuration script mysqlserver white and black lists to specify the database sql file backup to use git version control under localserver specified directory,
See git version control changes to the database table data

Pre-configured from localserver-> mysqlserver exemption password (configuration)

localserver (



#! / Bin / bash

#created by lihuibin
#date 2013-8-30
#desc backup mysqlsql file from mysqlserver to localserver

tar_path = "/ root / mysql_backup"

ssh root@ /root/shell/db_backup.sh
[-d $ Tar_path] && cd $ tar_path; git pull || git clone root@ /root/shell/mysql_backup.git



mysqlserver (

Assumption mysqlserver server has testdb1, testdb2, exdb1, exdb2 four databases

Script Location: /root/shell/db_backup.sh


#! / Bin / bash
#created by lihuibin
#date 2013-8-30
#desc exec mysqldump mysqlsql file from mysqlserver to git

time = `date '+% F% R'`
mysql_user = "backup_user"
mysql_password = "backup_passwd"
mysql_host = ""
mysql_port = "3306"

tar_path = / root / shell / mysql_backup
Database list backup_db_arr = ( "testdb1" "testdb2") # need to back up
# Backup_db_arr = ()
exclude_db_arr = ( "exdb1" "exdb2") # list exclude database backup when backup_db_arr is empty, exclude_db_arr into force, not empty only valid backup_db_arr

[-d $ Tar_path]
is_first_backup = $?

in_array () {
  local hay needle = $ 1
  for hay; do
      [[$ Hay == $ needle]] && return 0
  return 1

backup_length = $ {# backup_db_arr [@]}
#echo $ backup_length
exclude_length = $ {# exclude_db_arr [@]}
#echo $ exclude_length;
#in_array "dopool_blog" $ {backup_db_arr [@]} && echo hit || echo miss
for dbname in `mysql -h $ mysql_host -P $ mysql_port -u $ mysql_user -p $ mysql_password -e" show databases "| sed '1,2d'`
    if [$ backup_length -gt 0]; then
        in_array $ dbname $ {backup_db_arr [@]} || continue
    elif [$ backup_length -eq 0 -a $ exclude_length -gt 0]; then
        in_array $ dbname $ {exclude_db_arr [@]} && continue
    for tablename in `mysql -h $ mysql_host -P $ mysql_port -u $ mysql_user -p $ mysql_password -e" show tables from $ dbname "| sed '1d'`
        mkdir -p $ tar_path / $ dbname /
        / Usr / bin / mysqldump --lock-tables = TRUE --extended-insert = FALSE --complete-insert = TRUE -h $ mysql_host -P $ mysql_port -u $ mysql_user -p $ mysql_password $ dbname $ tablename> $ tar_path /$dbname/$tablename.sql

init_git () {
tar_path = `dirname $ 1`
dir_name = `basename $ 1`
cd $ 1
git init
git add.
git commit -a -m "init $ time"
cd $ tar_path
git clone --bare $ dir_name /
rm -rf $ dir_name
git clone $ dir_name.git

[$ Is_first_backup -eq 1] && init_git $ tar_path || {
                                                    cd $ tar_path;
                                                    git add.;
                                                    git commit -a -m "back up $ time";
                                                    git push;


After the implementation of the script, you can combine the git tig, diff command to check each backup version of the database table changes
- Installation and configuration of Hadoop under Linux (Server)
- Oracle 12c In-Memory Study (Database)
- To install PostgreSQL 9.4 (Database)
- Git uses a basic tutorial (Linux)
- RedHat command line and graphical interface switching (Linux)
- OpenSUSE 13.1 OpenSUSE 12.3 and how to install Cinnamon 2.2 Desktop (Linux)
- Cygwin install Python MySQLdb (Linux)
- Linux Troubleshooting: How to save the status of the SSH session is closed (Linux)
- Different between Linux file path and the windows (Linux)
- Ubuntu 10.10 install Oracle 10g graphic tutorials (Database)
- EXP-00091 Error resolved (Database)
- 17 How to install the Ubuntu 14.04 and Linux Mint Kodi14 (XBMC) (Linux)
- Syncthing: Private Security Synchronization tool to synchronize files between computers / folder (Linux)
- Workaround CentOS error message during compilation PHP5 common (Linux)
- Android recyclerview cardview (Programming)
- Linux file compression and archiving (Linux)
- To use Linux to create a secure managed gateway (Linux)
- Linux iptables firewall settings (Linux)
- Struts2 : combobox label use (Programming)
- Caffe + Ubuntu 14.04 64bit + CUDA 6.5 configuration instructions (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.