MySQL的備份方式,目前我想到的有五種,有可能還有 1,mysqldump方式,加上具體參數(shù)名(單庫,多庫,觸發(fā)器,存儲過程,表結(jié)構(gòu),字符集,single-transaction,等等) 2,mysqlhotcopy 只能備份myisam數(shù)據(jù)表備份,速度相當(dāng)快,因為是文件拷貝,可能瞬間被鎖表
MySQL的備份方式,目前我想到的有五種,有可能還有
1,mysqldump方式,加上具體參數(shù)名(單庫,多庫,觸發(fā)器,存儲過程,表結(jié)構(gòu),字符集,–single-transaction,等等)
2,mysqlhotcopy 只能備份myisam數(shù)據(jù)表備份,速度相當(dāng)快,因為是文件拷貝,可能瞬間被鎖表,任何的數(shù)據(jù)操作,比如插入和更新都會掛起。
3,LVM的快照功能進行數(shù)據(jù)庫分區(qū)的備份,這種方法是利用的邏輯卷的鏡像功能,對整個分區(qū)進行在線備份,這種備份數(shù)據(jù)量大,而且備份性能低下,因為每次備份都是整個鏡像,不能針對數(shù)據(jù)做備份。桶裝備份
4,開啟二進制同步日志功能,主從復(fù)制,從機器做備份功能。
5,在線的熱備份,采用開源的 Xtrabackup 備份工具對innodb 數(shù)據(jù)表進行在線備份,測試階段。
下面是備份的xtrabackup的測試例子。
[@root.localhost.nova ~]# /usr/bin/innobackupex-1.5.1 –user=root –defaults-file=/home/mysql/my.cnf –socket=/home/mysql/mysql.sock –database=serverinfo –slave-info –stream=tar /root/ |gzip > /root/bak_mysql.tar.gz
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy.
All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackup
prints “innobackup completed OK!”.
innobackupex: Using mysql Ver 14.12 Distrib 5.0.83, for pc-linux-gnu (i686) using readline 5.1
innobackupex: Using mysql server version 5.0.83-community-log
innobackupex: Created backup directory /root
090823 17:37:51 innobackupex: Starting mysql with options: –unbuffered –user=root –socket=/home/mysql/mysql.sock
090823 17:37:51 innobackupex: Connected to database with mysql child process (pid=28803)
090823 17:37:55 innobackupex: Connection to database server closed
090823 17:37:55 innobackupex: Starting ibbackup with command:
xtrabackup –defaults-file=/home/mysql/my.cnf –backup –suspend-at-end
–log-stream –target-dir=./
innobackupex: Waiting for ibbackup (pid=28809) to suspend
innobackupex: Suspend file ‘/home/mysql/xtrabackup_suspended’
xtrabackup: suspend-at-end is enabled.
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /home/mysql
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 4194304
xtrabackup: Stream mode.
>> log scanned up to (0 85364)
090823 17:37:57 innobackupex: Continuing after ibbackup has suspended
innobackupex: Starting to backup InnoDB tables and indexes
innobackupex: from original InnoDB data directory ‘/home/mysql’
innobackupex: Backing up as tar stream ‘ibdata1′
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserver.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserverlog.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_repairhistory.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfo.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfolog.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserver.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserverlog.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_user.ibd’
090823 17:37:58 innobackupex: Starting mysql with options: –unbuffered –user=root –socket=/home/mysql/mysql.sock
090823 17:37:58 innobackupex: Connected to database with mysql child process (pid=28834)
>> log scanned up to (0 85364)
090823 17:38:02 innobackupex: Starting to lock all tables…
>> log scanned up to (0 85364)
>> log scanned up to (0 88314)
>> log scanned up to (0 88415)
090823 17:38:20 innobackupex: All tables locked and flushed to disk
090823 17:38:20 innobackupex: Starting to backup .frm, .MRG, .MYD, .MYI,
innobackupex: .TRG, .TRN, and .opt files in
innobackupex: subdirectories of ‘/home/mysql’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserver.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserverlog.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_repairhistory.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfo.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfolog.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserver.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserverlog.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_user.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/db.opt’
090823 17:38:20 innobackupex: Finished backing up .frm, .MRG, .MYD, .MYI, .TRG, .TRN, and .opt files
innobackupex: Resuming ibbackup
xtrabackup: The latest check point (for incremental): ‘0:88415′
>> log scanned up to (0 88415)
xtrabackup: Transaction log of lsn (0 85364) to (0 88415) was copied.
090823 17:38:24 innobackupex: All tables unlocked
090823 17:38:24 innobackupex: Connection to database server closed
innobackupex: Backup created in directory ‘/root’
innobackupex: MySQL binlog position: filename ”, position
innobackupex: MySQL slave binlog position: master host ”, filename ”, position
090823 17:38:24 innobackupex: innobackup completed OK!
innobackupex: You must use -i (–ignore-zeros) option for extraction of the tar stream.
[@root.localhost.nova ~]#
[@root.localhost.nova ~]# ls -ltr
total 11752
drwxr-xr-x 2 oracle ftp 4096 Apr 20 15:43 linux
-rw-r–r– 1 root root 17969 Apr 20 15:43 linux.tgz
-rw-r–r– 1 root root 4698 Jun 5 16:08 install.sh
-rw-r–r– 1 root root 3565 Jun 18 11:21 HP-set.sh
-rw-r–r– 1 root root 98676 Jul 27 13:33 install.log.syslog
-rw-r–r– 1 root root 68464 Jul 27 13:33 install.log
-rw-r–r– 1 root root 1299 Jul 27 13:33 anaconda-ks.cfg
-rw-rw—- 1 mysql mysql 10485760 Aug 14 10:57 ibdata1
-rw-r–r– 1 root root 1230176 Aug 23 17:12 xtrabackup-0.7-1.rhel4.x86_64.rpm
-rw-r–r– 1 root root 44998 Aug 23 17:38 bak_mysql.tar.gz
[@root.localhost.nova ~]#
[@root.localhost.nova tmp]# ls -lR
.:
total 10336
-rw-r–r– 1 root root 259 Aug 23 17:37 backup-my.cnf
-rw-r–r– 1 root root 44998 Aug 23 17:43 bak_mysql.tar.gz
-rw-rw—- 1 mysql mysql 10485760 Aug 23 17:28 ibdata1
-rw-r–r– 1 root root 0 Aug 23 17:37 mysql-stderr
-rw-r–r– 1 root root 506 Aug 23 17:38 mysql-stdout
drwxr-xr-x 2 root root 380 Aug 23 17:43 serverinfo
-rw-r–r– 1 root root 1 Aug 23 17:38 xtrabackup_binlog_info
-rw-r–r– 1 root root 60 Aug 23 17:38 xtrabackup_checkpoints
-rw-r–r– 1 root root 5632 Aug 23 17:38 xtrabackup_logfile
-rw-r–r– 1 root root 53 Aug 23 17:38 xtrabackup_slave_info
./serverinfo:
total 1020
-rw-rw—- 1 mysql mysql 61 Aug 12 19:59 db.opt
-rw-rw—- 1 mysql mysql 34626 Aug 12 20:00 simsys_djgameserver.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_djgameserver.ibd
-rw-rw—- 1 mysql mysql 8760 Aug 12 20:00 simsys_djgameserverlog.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_djgameserverlog.ibd
-rw-rw—- 1 mysql mysql 12944 Aug 12 20:00 simsys_repairhistory.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_repairhistory.ibd
-rw-rw—- 1 mysql mysql 26072 Aug 12 20:00 simsys_serverinfo.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_serverinfo.ibd
-rw-rw—- 1 mysql mysql 8760 Aug 12 20:00 simsys_serverinfolog.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_serverinfolog.ibd
-rw-rw—- 1 mysql mysql 56550 Aug 12 20:00 simsys_tlgameserver.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_tlgameserver.ibd
-rw-rw—- 1 mysql mysql 8760 Aug 12 20:00 simsys_tlgameserverlog.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_tlgameserverlog.ibd
-rw-rw—- 1 mysql mysql 8646 Aug 12 20:00 simsys_user.frm
-rw-rw—- 1 mysql mysql 98304 Aug 14 10:57 simsys_user.ibd
備份出來的文件是:bak_mysql.tar.gz,解壓方法:tar zxvfi bak_mysql.tar.gz
恢復(fù)時候就采用復(fù)制文件,覆蓋,然后mysqldump方式導(dǎo)入導(dǎo)出。
http://www.imdba.cn/2009/08/31/mysqlbakup-eg/
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com