MySQL automated backup solution

Source: Internet
Author: User
Mysql backup mainly includes hot backup and cold backup. Here, hot backup is used, that is, the SQL statement exported by mysqldump is used for backup. In this case, backup is performed every morning.

Mysql backup mainly includes hot backup and cold backup. Here, hot backup is used, that is, the SQL statement exported by mysqldump is used for backup. In this case, backup is performed every morning.

1. Configure the Database Server

1. Write the mysql automatic backup script

Mysql backup mainly includes hot standby and Cold Standby. Hot Standby is used here, that is, the SQL statement exported by mysqldump is used for backup.

# Vi/etc/mysqlback. sh

#! /Bin/bash

DB_NAME = "luwenju" // database to be backed up

DB_USER = "luwenju" // database username

DB_PASS = "luwenju" // Database Password

BIN_DIR = "/usr/local/mysql/bin" // mysql environment variable

BACK_DIR = "/opt" // backup file to save data

DATE = "'date + % Y % m % d '"

$ BIN_DIR/mysqldump-opt-u $ DB_USER-p $ DB_PASS $ DB_NAME> $ BACK_DIR/luwenju _ $ DATE. SQL

# Chmod + x/etc/mysqlback. sh

Test

#/Etc/mysqlback. sh

# Ls/opt/

Luwenju_20151126. SQL

2. Set a regular backup cycle

In this case, backup is performed every morning. The specific backup cycle is based on the specific application.

# Crontab-e

0 0 ***/etc/mysqlback. sh

#/Etc/init. d/crond restart

3. Install rsync

# Tar zxvf rsync-3.0.8.tar.gz

# Cd rsync-3.0.8

#./Configure & make install

Create a configuration file and add the following content:

# Vi/etc/rsync. conf

Uid = nobody

Gid = nobody

Use chroot = no

Max connections = 10

Pid file =/var/run/rsyncd. pid

Lock file =/var/run/rsyncd. lock

Log file =/var/log/rsyncd. log

Port = 873

Timeout = 300

[Backup]

Read only = yes // read-only mode

List = yes

Ignore errors

Comment = This is a file back

Path =/opt // directory to be synchronized

Auth users = test // verify the user

Secrets file =/etc/rsync. passwd // verify the password path

Hosts allow = 119.232.33.246 // client that can be connected

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.