Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 知乎專欄 | 視頻教程 | About

21.5. Backup and Recovery

21.5.1. Import / Export

21.5.1.1. Export(Backup)

		
mysqldump -hlocalhost -proot -p**** mydb > mydb.sql
		
		

gzip

		
mysqldump -hlocalhost -proot -p**** mydb | gzip > mydb.sql.gz
		
		

21.5.1.2. Import(Recovery)

		
mysql -hlocalhost -proot -p**** mydb < mydb.sql
		
		

gunzip

		
gunzip mydb.sql.gz -c | mysql -hlocalhost -proot -p**** mydb
		
		

21.5.1.3. xml

export xml

$ mysqldump -uusrname -ppasswd -X -t database table -r filename.xml
		

21.5.1.4. 備份表數據

SELECT * INTO OUTFILE 'file_name' FROM tbl_name
LOAD DATA INFILE 'file_name' REPLACE INTO TABLE tbl_name
		

21.5.1.5. source

		
mysql> use your_db
mysql> SOURCE database.sql
		
		

21.5.1.6. 使用 mysqlhotcopy 備份 MyISAM 引擎的資料庫

shell> mysqlhotcopy db_name /path/to/some/dir
mysql:~# mysqlhotcopy --user=neo --password=chen shop /tmp/backup
Locked 100 tables in 0 seconds.
Flushed tables (`shop`.`account_log`, `shop`.`ad`, `shop`.`ad_custom`, `shop`.`ad_position`, `shop`.`admin_action`,
`shop`.`admin_log`, `shop`.`admin_message`, `shop`.`admin_user`, `shop`.`adsense`, `shop`.`affiliate_log`,
...
...
...
`shop`.`user_rank`, `shop`.`users`, `shop`.`virtual_card`, `shop`.`volume_price`, `shop`.`vote`, `shop`.`vote_log`,
`shop`.`vote_option`, `shop`.`wholesale`) in 0 seconds.
Copying 299 files...
Copying indices for 0 files...
Unlocked tables.
mysqlhotcopy copied 100 tables (299 files) in 0 seconds (0 seconds overall).
		

21.5.1.7. AutoMySQLBackup

https://sourceforge.net/projects/automysqlbackup/

21.5.1.8. xtrabackup - Open source backup tool for InnoDB and XtraDB.

https://launchpad.net/percona-xtrabackup

21.5.1.8.1. Percona yum Repository
$ rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
			
# yum search xtrabackup
================================================================ N/S Matched: XtraBackup =================================================================
holland-xtrabackup.noarch : Xtrabackup plugin for Holland
percona-xtrabackup.x86_64 : XtraBackup online backup for MySQL / InnoDB
percona-xtrabackup-debuginfo.x86_64 : Debug information for package percona-xtrabackup
percona-xtrabackup-test.x86_64 : Test suite for Percona Xtrabackup
			
# yum install percona-xtrabackup
			
21.5.1.8.2. Creating an Incremental Backup
xtrabackup --backup --target-dir=/data/backups/base --datadir=/var/lib/mysql/
			

21.5.2. Snapshot Backup

21.5.2.1. LVM Snapshot

		
# mysql –uroot –pmysql
mysql> flush tables with read lock;
mysql>flush logs;
mysql>system lvcreate -L1024M -s -n snap0 /dev/vg00/lvol00
mysql>show master status;
mysql>unlock tables;
mysql>quit
		
		

21.5.2.2. Btrfs Snapshot

# btrfs subvolume snapshot /data /data/backup_2013-03-20
Create a snapshot of '/data' in '/data/backup_2013-03-20'

btrfs subvolume list /data
ID 315 gen 172 top level 5 path backup_2013-03-10
ID 320 gen 178 top level 5 path backup_2013-03-20