Database structure version control

Source: Internet
Author: User
Tags diff

Help
./backup.mysql.struct.shusage:./backup.mysql.struct.sh {Init|start|stop|status|restart}
Create Backup user for your database.
CREATE USER ' backup ' @ ' localhost ' identified by ' Sajepom6bapomofod7xo3e1a52vepe '; GRANT SELECT, LOCK TABLES on *. * to ' backup ' @ ' localhost '; FLUSH privileges; SHOW GRANTS for ' backup ' @ ' localhost ';
Database Connect Infomation
backup_host= "localhost" backup_user= "Netkiller" backup_pass= "Chen" backup_dbname= "Test AABBCC" backup_dir=~/backup
Initialize The Working directory
$./backup.mysql.struct.sh initinitialized empty Git repository in/home/neo/backup/.git/
Start
$./backup.mysql.struct.sh Start
Stop
$./backup.mysql.struct.sh Stop
Status
$./backup.mysql.struct.sh status19837 pts/0 S 0:00/bin/bash./backup.mysql.struct.sh start
Diff
$ cd ~/backup$  Git diff head^ test.sqldiff --git a/localhost/test.sql b/localhost/test.sqlindex  a749b5a. 402d6d1 100644--- a/localhost/test.sql+++ b/localhost/test.sql@@ -53,6 +53,7 @@  DROP TABLE IF EXISTS  ' test ';  /*!40101 set character_set_client =  utf8 */; CREATE TABLE  ' Test '   (    ' id '  int (one)  default  NULL,+   ' key '  char (+)  DEFAULT NULL,    ' Val '  char (Ten)   default null )  ENGINE=BLACKHOLE DEFAULT CHARSET=latin1; /*!40101 SET  character_set_client =  @saved_cs_client  */; 

 

#!/bin/bash####################################  $Id $# author: [email protected]# home : http://netkiller.github.com#################################### select  ' user ',  ' host ',   ' password '  FROM  ' mysql '. ' User ';# create user  ' backup ' @ ' localhost '   identified by  ' Sajepom6bapomofod7xo3e1a52vepe ';# grant select, lock tables  on *.* to  ' backup ' @ ' localhost '; # flush privileges;# show grants for   ' backup ' @ ' localhost '; ################################## #BACKUP_HOST = "localhost" backup_user= "Backup" Backup_pass= "Chen" backup_dbname= "test aabbcc" backup_dir=~/backup################################### #NAME = Backup.mysql.structbasedir= '/www ' prog= $BASEDIR/bin/$ (basename $0) logfile=/var/tmp/$NAME. logPIDFILE=/var/ tmp/$NAME. pidmysqldump= "/usr/bin/mysqldump" mysqldump_opts= "-h  $BACKUP _host -u$backup_user -p$ Backup_pass --skip-comments -d "################################### #umask  0077############################################### rotate=60loop=30############################################# #function  backup () {test ! -d  "$BACKUP _dir"  && echo  "error:  $BACKUP _dir isn ' t a directory."  && exit 0cd  $BACKUP _dirfor dbname in  $BACKUP _dbnamedotest !  -d  "$BACKUP _dir/$BACKUP _host"  && mkdir -p  "$BACKUP _dir/$BACKUP _host" $ mysqldump  $MYSQLDUMP _opts  $dbname  >  $BACKUP _dir/$BACKUP _host/$dbname. sqldonetimepoint=$ (date -u +%y-%m-%d.%h:%m:%s) git add .git commit --quiet -m  "$TIMEPOINT " > /dev/null}function start () {if [ -f " $PIDFILE " ]; thenecho  $PIDFILEexit  2fitest ! -w  $BACKUP _dir && echo  "error:  $BACKUP _ Dir is un-wrIteable. "  && exit 0 for  ( ; ; ) dobackupsleep  $LOOPdone   &echo $! >  $PIDFILE}function stop () {   [ -f  $PIDFILE   ] && kill  ' cat  $PIDFILE '  && rm -rf  $PIDFILE}function  init () { if [ ! -d  $BACKUP _dir ]; thenmkdir -p  "$BACKUP _dir" cd  $BACKUP _dirgit init    fibackup}case  "$"  in  start)    start;;   stop)    stop;;   status)    ps ax | grep $ (basename $0)  | grep  -v grep | grep -v status;;   restart)    stopstart;; init) init;; *) echo $ "Usage: $0 {init|start|stop|status|restart}" exit 127esac exit $?


Database structure version control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.