Back up MySQL using mysqlhotcopy (1)

Source: Internet
Author: User
Tags perl script

Guidance:I believe many people have used mysqldump, which is easy to store, but slow. FastestBackupThe method is to copy the data directory directly. However, in general, closeMySQLThe service can be done, or when you copy, there will be people reading and writing tables, it will be too much trouble. UseMysqlhotcopyThe above problems will not exist. He can perform hot backup. His backup is very fast. Next I will introduce you to this useful MySQL database backup method.

Mysqlhotcopy is a Perl script originally written and provided by Tim Bunce. It uses lock tables, flush tables, and cp or scp to quickly back up databases. It is the fastest way to back up a database or a single table, but it can only run on the machine where the database directory is located. Mysqlhotcopy is only used to back up MyISAM. It runs in Unix and NetWare

For usage instructions, see the following script. Add it to crotab.

Reference content is as follows:
#! /Bin/sh

# Name: mysqlbackup. sh

# PS: MySQL DataBase Backup, Use mysqlhotcopy script.

# Last Modify: 2008-06-12

# Define variables. Modify the variables as needed

# Define the directory where the script is located

ScriptsDir = 'pwd'

# Database Data Directory

DataDir =/var/lib/mysql

# Data Backup Directory

TmpBackupDir =/tmp/mysqlblackup

BackupDir =/backup/mysql

# Username and password used to back up the database

MysqlUser = root

MysqlPWD = 'you password'

# If the temporary Backup directory exists, clear it. If it does not exist, create it.

If [[-e $ tmpBackupDir]; then

Rm-rf $ tmpBackupDir /*

Else

Mkdir $ tmpBackupDir

Fi

# Create a backup directory if it does not exist

If [[! -E $ backupDir]; then

Mkdir $ backupDir

Fi

# Obtain the database backup list, where you can filter databases that do not want to be backed up

For databases in 'Find $ dataDir-type d | \

Sed-e "s/\/var \/lib \/mysql \ //" | \

Sed-e "s/test //" '; do

If [[$ databases = ""]; then

Continue

Else

# Backing up a database

/Usr/bin/mysqlhotcopy -- user = $ mysqlUser -- password = $ mysqlPWD-q "$ databases" $ tmpBackupDir

DateTime = 'date "+ % Y. % m. % d % H: % M: % S "'

Echo "$ dateTime Database: $ databases backup success! "> MySQLBackup. log

Fi

Done


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.