Manipulating MySQL's shell script

Source: Internet
Author: User
Tags date ftp mysql sleep svn rsync backup linux

Directory

1.MySQL Hot-Backup script

2. Synchronize server with FTP

3.Keepalived Monitoring and switching scripts

4.SVN batch backup of the version library

5. Automatically monitor ADSL and dial number

6.Linux Batch Build Generation account (updated October 11)

7. Test whether the host in the LAN Alive (October 11 update)

One, the MySQL hot backup script

This is one of the backup methods of MySQL, the script is as follows:

#!/bin/bash

Path=/usr/local/sbin:/usr/bin:/bin

# The Directory of Backup

Backdir=/usr/mysql_backup

# The Password of MySQL

Rootpass=password

# remake The Directory of Backup

RM-RF $BACKDIR

Mkdir-p $BACKDIR

# get the Name of Database

dblist= ' Ls-p/var/lib/mysql | grep/| tr-d/'

# Stole a peek at the way my colleague wrote the script, and found out that he had directly dblist each hand.

# database less situation is possible, if the database is hundreds or more, hehe

# Backup with Database

For dbname in $DBLIST

Todo

Mysqlhotcopy $dbname-u root-p $ROOTPASS $BACKDIR | Logger-t mysqlhotcopy

Done

Many system administrators like to use Mysqldump--opt to back up the database, because it is simpler, I do not repeat here.

Second, the use of FTP synchronization server

Many system administrators prefer to use rsync to synchronize data between two servers, but we prefer to use FTP to achieve the benefits:

1.FTP consumes more bandwidth than rsync, so it's better for synchronizing databases (especially hundreds of G data)

2. Very convenient configuration, especially with PUREFTPD

3.rsync Advantage is the rapid mass synchronization of small files, such as the level two directory or three-level catalog of the bulk of the picture, etc.

Basically FTP and rsync synchronization each have advantages, look at the choice of system administrator. The following is the shell scripting method for FTP synchronization that is described in this section:

Ftpolddate= ' Date +%y-%m-%d-d ' -60 days '

#在FTP定义60天间的日期变量, is to save 60 days of data on the FTP side, late deletion.

host=192.168.4.199

Ftp_username=db

Ftp_password=password

CD ${backdir}/${date}

Ftp-i-n-v "!

Open ${host}

User ${ftp_username} ${ftp_password}

Bin

CD ${ftpolddate}

Mdelete *

Cd

RmDir ${ftpolddate}

mkdir ${date}

CD ${date}

Mput *

Bye

!

Iii. keepalived monitoring and switching scripts

Implementation features are as follows: For nginx+keepalived, write nginx monitoring scripts nginx_ Pid.sh, placed in the background has been monitoring the nginx process, such as the process disappears, try to restart the Nginx, if the failure immediately stop the local keepalived service, so that another load balancer to take over. The script details are as follows:

#!/bin/bash

While:

Todo

Nginxpid= ' ps-c nginx--no-header | Wc-l '

If [$nginxpid-eq 0];then

Ulimit-shn 65535 #在并发数很大的情况下, the number of connections is too small can cause Linux crazy error, so directly before the Nginx start to define

/usr/local/nginx/sbin/nginx

Sleep 5

If [$nginxpid-eq 0];then

/etc/init.d/keepalived stop

Fi

Fi

Sleep 5

Done

Related instructions can refer to my network channel on the "Enterprise-class web load balancing high availability of lvs+keepalived" article.

Four, SVN version of the repository of bulk backups

The realization of its function is quite simple, mainly with the Svnadmin hotcopy, this dongdong function is very powerful, I often used SVN version of the transfer (by the way, the last time accidentally mistakenly operation will be deleted, it is easy to use the svnadmin hotcopy to restore it over).

For project in test project Svntest

Todo

CD ${svndir}

${svnadmin} hotcopy ${project} ${backdir}/${date}/${project}--clean-logs

CD ${backdir}/${date}

Tar zcvf ${project}_svn_${date}.tar.gz ${project} >/dev/null

RM-RF ${project}

echo "Repository: ${project} backup done into ${backdir}/${date}/successful!"

Related Article

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.