mysql:5.6.29
xtrabackup:2.2.10
mysql數據目錄:/data/mysql
mysql備份目錄:/data/dbbak/full #確保有足夠的磁盤空間
1、安裝依賴
yum -y install libaio perl-Time-HiRes perl-DBD-MySQL perl-IO-Socket-SSL rsync.x86_64
2、安裝xtrabackup
rpm -ivh percona-xtrabackup-2.2.10-1.el6.x86_64.rpm
3、在數據庫創建備份賬號
mysql> CREATE USER 'bkpuser'@'localhost' IDENTIFIED BY 's3cret'; mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT,Process ON *.* TO 'bkpuser'@'localhost'; mysql> FLUSH PRIVILEGES;
4、使用xbstream備份
time innobackupex --user=bkpuser --password=s3cret --no-timestamp --defaults-file=/etc/my.cnf /data/dbbak/full --tmpdir=/data/dbbak/full -stream=xbstream|gzip - > /data/dbbak/full/full.xbstream.gz 161124 10:08:50 innobackupex: Connection to database server closed 161124 10:08:50 innobackupex: completed OK! real 0m37.613s user 0m28.506s sys 0m3.186s 解壓 time gzip -d full.xbstream.gz real 0m26.678s user 0m13.405s sys 0m2.354s time xbstream -x <full.xbstream real 1m7.379s user 0m6.055s sys 0m11.173s
5、使用tar備份
time innobackupex --user=bkpuser --password=s3cret --no-timestamp --defaults-file=/etc/my.cnf /data/dbbak/full --tmpdir=/data/dbbak/full --stream=tar |gzip - > /data/dbbak/full/full.tar.gz innobackupex: You must use -i (--ignore-zeros) option for extraction of the tar stream. 161124 10:09:53 innobackupex: completed OK! real 0m34.934s user 0m26.500s sys 0m2.816s 解壓 time tar -ixzvf /data/dbbak/full/full.tar.gz real 0m27.310s user 0m12.818s sys 0m3.735s 或者 gzip -d /data/dbbak/full/full.tar.gz tar -ixvf /data/dbbak/full/full.tar.gz 推薦使用tar -ixzvf /data/dbbak/full/full.tar.gz 解壓
6、對比2種導出的文件大小
[root@VM_166_129 full]# ll total 95232 -rw-r--r-- 1 root root 48704253 Nov 24 10:09 full.tar.gz -rw-r--r-- 1 root root 48809971 Nov 24 10:23 full.xbstream.gz
7、總結
使用--stream=tar備份,壓縮、解壓、已經壓縮后的大小都優於-stream=xbstream,推薦使用--stream=tar方式壓縮,解壓時還可以配合tar。
