Use mysqlhotcopy to regularly back up MySQL Databases in CentOS (MyISAM storage engine)

Source: Internet
Author: User
Tags install perl

In CentOS, mysqlhotcopy is used to regularly back up MySQL databases (MyISAM storage engine). mysqlhotcopy and mysqldump are compared: the former is a COPY in the sense of a fast file, and the latter is a collection of SQL statements on the database. The former can only run on the machine where the database directory is located, and the latter can be used on a remote client, but the backup files are still stored on the server. In the same place as www.2cto.com, both lock tables and unlock tables are executed online. To restore the data, you only need to COPY the backup file to the source directory and overwrite the data. Then, you need to import the SQL file to the original database. (Source or mysql <bakfile. SQL) the former is only applicable to the MyISAM engine, and then can be used by both the MyISAM engine and the InodDB engine. the former must install the perl-DBD-mysql package before use, while the latter does not. before using mysqlhotcopy, install perl-DBI and DBD-mysql: www.2cto.com 1yum-y install perl-DBIShell. The script is as follows: 01 # Name: mysqlbackup. sh02 # PS: MySQL DataBase Backup, Use mysqlhotcopy script.03 # Last Modify: 2008-06-1204 # define variables, modify 05 # definition script directory 06 scriptsDir = 'pwd' 07 # database data directory 08 dataDir =/usr/local/mysql/var/09 # data Backup Directory 10 tmpBackupDir =/tmp/mysqlblackup11backupDir =/home/backup/mysql12 # username and password used to back up the database 13 mysqlUser = root14mysqlPWD = '000000' 15 # If the temporary backup directory exists, clear it. If it does not exist, create it 16if [[-e $ tmpBackupDir]; then17 rm-rf $ tmpBackupDir/* 18else19 mkdir $ tmpBackupDir20fi21 22 # create javasc23if [[! -E $ backupDir]; then24 mkdir $ backupDir25fi26 # obtain the database backup list, here you can filter out the databases that do not want to back up 27 28for databases in 'Find $ dataDir-type d | \ 29 30sed-e "s/\/usr \/local \/mysql \/var \ /// "| \ 31 32sed-e" s/test //"'; do33 34if [[$ databases = ""]; then35 36 continue37else38 # backup data 39 40/usr/local/mysql/bin/mysqlhotcopy -- user = $ mysqlUser -- password = $ mysqlPWD-q "$ databases" $ tmpBackupDir41 42 dateTime =' date "+ % Y. % m. % d % H: % M: % S "'43 44 echo" $ dateTime Database: $ databases backup success! "> MySQLBackup. log45 46fi47 48done49 50 # compressing the backup file 51 52 date = 'date-I '53 54cd $ tmpBackupDir55 56tar czf $ backupDir/mysql-1_date.tar.gz. /57 58 # En <span> </span> d. Add the scheduled task 130 5 ***/root/mysqlbackup. sh> mysqlbackup. log 2> & 1 how to restore? 1. Stop the mysql server. 2. Copy the backup database directory to the mysql data directory. 3. Change the user (such as mysql) whose directory owner is running on the mysql server ). 4. Start the mysql server

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.