harumaki.net

インフラ屋の覚書や、ラーメン食べある記とか。

backup MySQL 運用

[MySQL] Percona xtrabackupを試す(Ver2.0.8)

投稿日:2013年9月11日

Last Updated on 2021年7月4日 by かんりにん

PerconaのMySQL用バックアップツール”xtrabackup”をテスト環境にてお試し。
バックアップ対象のMySQLは、Percona謹製のMySQLだけでなく、公式版のMySQLにも使えるので、すでに稼働中のMySQL DBサーバーにXtraBackupを追加してもOK。
検証に使った環境はAWS EC2にてCentOS6+MySQL5.5です。

■参考:お世話になっております!

Percona xtrabackup公式サイト
GitHub percona-xtrabackup
Percona xtrabackup:downloads
インストールガイド(英語)
バージョン対応情報

■導入検証

▼事前準備

非同期処理ライブラリlibev、Perlの時間計測モジュール”Time::HiRes”が必要となるので、先にインストール。
“Time::HiRes”はRPMパッケージでは”perl-Time-HiRes”と置き換えてインストール。

# yum install libev perl-Time-HiRes

そのほか、必要なライブラリがあれば追加する。

▼試しにインストール(RPM版)

公式サイトからRPMをダウンロード。2.0.8は2013年09月3日リリース

1.RPMパッケージのダウンロード

# wget https://www.percona.com/downloads/XtraBackup/XtraBackup-2.0.8/RPM/rhel6/x86_64/percona-xtrabackup-20-2.0.8-587.rhel6.x86_64.rpm
# wget https://www.percona.com/downloads/XtraBackup/XtraBackup-2.0.8/RPM/rhel6/x86_64/percona-xtrabackup-20-debuginfo-2.0.8-587.rhel6.x86_64.rpm
# wget https://www.percona.com/downloads/XtraBackup/XtraBackup-2.0.8/RPM/rhel6/x86_64/percona-xtrabackup-20-test-2.0.8-587.rhel6.x86_64.rpm

debuginfoやtestは特に必要なさそうだったので、省略しても問題なさそう。

2.Percona GPG Keyのインストール

※GPG KeyのURLはこちらを参照のこと。

# rpm --import http://www.percona.com/downloads/RPM-GPG-KEY-percona

3.インストールテスト

# rpm -ivh --test percona-xtrabackup-20-2.0.8-587.rhel6.x86_64.rpm
Preparing...                ########################################### [100%]

4.インストール

# rpm -ivh percona-xtrabackup-20-2.0.8-587.rhel6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:percona-xtrabackup-20  ########################################### [100%]

おまけ:汎用バイナリも提供

公式サイトのダウンロードページにて、ディストリビューションに依存しない、汎用のバイナリとスクリプトも提供されており、インストールの手間をかけずに利用することが可能。

利用にあたっては。innobackupex実行時に実行コマンドであるxtrabackupを同時に起動するため、パスが通っている場所へコピーしてから実行することが条件。
CentOS6では、bin/以下のコマンドをすべて/usr/local/binにコピーして実行し、RPM版と同様の動作を確認。
そのほかのディストリビューションでは未確認のため、それぞれ確認する必要あり。

▼環境設定

xtrabackup独自のコンフィギュレーションファイルは無く、my.cnfに”[xtrabackup]”セクションを追記して、パラメータと設定値を追加するかたち。
“man xtrabackup”すると簡単な設定の案内が出てくるので、そちらを参考のこと。
※当たり前だけど、my.cnfへ設定を追加・適用する場合はプロセスの再起動が必要になるので、要注意。

– 超カンタンなmy.cnf設定例
manすると以下の設定が例として出てくるので、抜粋。

[xtrabackup]
target_dir = /data/backups/mysql/

▼バックアップを試してみる

1)xtrabackupコマンドでの実行

MySQLのデータディレクトリは/var/lib/mysql、
バックアップ先は今回はテストなので/tmp/xtrabackupを指定。
バックアップ先ディレクトリはコマンド実行前にmkdirしておく。

# xtrabackup --backup --user root --password <パスワード> --datadir=/var/lib/mysql/ --target-dir=/tmp/xtrabackup
xtrabackup version 2.0.8 for Percona Server 5.1.59 unknown-linux-gnu (x86_64) (revision id: 587)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /var/lib/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 = 5242880
>> log scanned up to (1015263)
[01] Copying ./ibdata1 to /tmp/xtrabackup/ibdata1
[01]        ...done
>> log scanned up to (1015263)
xtrabackup: The latest check point (for incremental): '1015263'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (1015263)

xtrabackup: Transaction log of lsn (1015263) to (1015263) was copied.

エクスポートされたデータをチェックをしてみると…

# ls -al /tmp/xtrabackup/
total 18472
drwxr-xr-x 2 root root     4096 Sep 10 16:17 .
drwxrwxrwt 7 root root     4096 Sep 10 16:17 ..
-rw-r----- 1 root root 18874368 Sep 10 16:17 ibdata1
-rw-r----- 1 root root       77 Sep 10 16:17 xtrabackup_checkpoints
-rw-r----- 1 root root     2560 Sep 10 16:17 xtrabackup_logfile

バックアップとして保存されたのは下記の3ファイル。

    ibdata1
    xtrabackup_checkpoints
    xtrabackup_logfile (バックアップ実行中のbinlogの差分)

ibdata*だけバックアップされてMyISAMのファイルがバックアップされなかったのは、なにかオプションが足りなかったのかな?
と思ったら、”innobackupex”コマンドだとInnoDB、MyISAM両方がバックアップされた。続きは以下を。

2)innobackupexコマンドでの実行

xtrabackupと異なり、InnoDB、MyISAM両方がバックアップされ、かつ詳細なログも出力された。

# innobackupex --user root --password rabbirabbi /tmp/xtrabackup/

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.

This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.

130910 17:33:51  innobackupex: Starting mysql with options:  --password=xxxxxxxx --user='root' --unbuffered --
130910 17:33:51  innobackupex: Connected to database with mysql child process (pid=3598)
130910 17:33:57  innobackupex: Connection to database server closed
IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".

innobackupex: Using mysql  Ver 14.14 Distrib 5.5.30, for Linux (x86_64) using readline 5.1
innobackupex: Using mysql server version Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

innobackupex: Created backup directory /tmp/xtrabackup/xtrabackup
130910 17:33:57  innobackupex: Starting mysql with options:  --password=xxxxxxxx --user='root' --unbuffered --
130910 17:33:57  innobackupex: Connected to database with mysql child process (pid=3624)
130910 17:33:59  innobackupex: Connection to database server closed

130910 17:33:59  innobackupex: Starting ibbackup with command: xtrabackup_55  --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/tmp/xtrabackup/2013-09-10_17-33-57 --tmpdir=/tmp
innobackupex: Waiting for ibbackup (pid=3631) to suspend
innobackupex: Suspend file '/tmp/xtrabackup/2013-09-10_17-33-57/xtrabackup_suspended'

xtrabackup_55 version 2.0.8 for Percona Server 5.5.16 Linux (x86_64) (revision id: 587)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /var/lib/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 = 5242880
>> log scanned up to (3377014)
[01] Copying ./ibdata1 to /tmp/xtrabackup/2013-09-10_17-33-57/ibdata1
[01]        ...done
>> log scanned up to (3377014)
xtrabackup: Creating suspend file '/tmp/xtrabackup/2013-09-10_17-33-57/xtrabackup_suspended' with pid '3631'

130910 17:34:00  innobackupex: Continuing after ibbackup has suspended
130910 17:34:00  innobackupex: Starting mysql with options:  --password=xxxxxxxx --user='root' --unbuffered --
130910 17:34:00  innobackupex: Connected to database with mysql child process (pid=3645)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
130910 17:34:02  innobackupex: Starting to lock all tables...
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
>> log scanned up to (3377014)
130910 17:34:12  innobackupex: All tables locked and flushed to disk

130910 17:34:12  innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/var/lib/mysql'
innobackupex: Backing up files '/var/lib/mysql/wordpress_test/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (11 files)
innobackupex: Backing up files '/var/lib/mysql/mysql/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (72 files)
innobackupex: Backing up files '/var/lib/mysql/wordpress_test2/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (12 files)
innobackupex: Backing up files '/var/lib/mysql/wordpress/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (34 files)
innobackupex: Backing up files '/var/lib/mysql/performance_schema/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18 files)
130910 17:34:12  innobackupex: Finished backing up non-InnoDB tables and files

130910 17:34:12  innobackupex: Waiting for log copying to finish

xtrabackup: The latest check point (for incremental): '3377014'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (3377014)

xtrabackup: Creating suspend file '/tmp/xtrabackup/2013-09-10_17-33-57/xtrabackup_suspended' with pid '3631'
xtrabackup: Transaction log of lsn (3377014) to (3377014) was copied.
130910 17:34:15  innobackupex: All tables unlocked
130910 17:34:15  innobackupex: Connection to database server closed

innobackupex: Backup created in directory '/tmp/xtrabackup/2013-09-10_17-33-57'
innobackupex: MySQL binlog position: filename 'mysql-bin.000013', position 107
130910 17:34:15  innobackupex: completed OK!

– 出力されたファイルを確認。

$ ls -al
合計 18504
drwxr-xr-x 7 root root     4096  9月 10 17:34 2013 .
drwxr-xr-x 3 root root     4096  9月 10 17:33 2013 ..
-rw-r--r-- 1 root root      260  9月 10 17:33 2013 backup-my.cnf
-rw-r----- 1 root root 18874368  9月 10 17:33 2013 ibdata1
drwxr-xr-x 2 root root     4096  9月 10 17:34 2013 mysql
drwxr-xr-x 2 root root     4096  9月 10 17:34 2013 performance_schema
drwxr-xr-x 2 root root     4096  9月 10 17:34 2013 wordpress
drwxr-xr-x 2 root root     4096  9月 10 17:34 2013 wordpress_test
drwxr-xr-x 2 root root     4096  9月 10 17:34 2013 wordpress_test2
-rw-r--r-- 1 root root       13  9月 10 17:34 2013 xtrabackup_binary
-rw-r--r-- 1 root root       23  9月 10 17:34 2013 xtrabackup_binlog_info
-rw-r----- 1 root root       77  9月 10 17:34 2013 xtrabackup_checkpoints
-rw-r----- 1 root root     2560  9月 10 17:34 2013 xtrabackup_logfile

バイナリログ、スロークエリログなどを除いて、主要なファイルがバックアップされ、かつバイナリログのポジションなども記載されたファイルが出力されている。バックアップとして必要なファイルは一通り揃っている感じ。
使い買ってもよさそうなので、引き続きリストア環境を用意して試してみたいところ。

ひとつ気づいたところとして、xtrabackupでは”–datadir=”を指定していたが、innobackupexでは”–datadir=”オプションが無い様子で”Unknown option”、”Bad command line arguments” などと叱られてしまった。
mysqlの設定情報を見ているようなので問題なく/var/lib/mysql以下のデータをバックアップしてくれたが、この違いはなんだろう?時間が合ったら要調査。
 

 

 

-backup, MySQL, 運用
-, , ,

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


関連記事

no image

ZABBIXインストール(1.1alpha7)

[pukiwiki]   **動作条件 [#l90318ac] -Apache >= 1.3.12 -MySQL (or PostgreSQL) >= 3.22 (7.0.2) -PHP >= 4.0 …

no image

CentOSにwmiクライアントを入れてみる

[pukiwiki] 何気に[[LINUX PACKAGE SEARCH>http://pkgs.org/]]でwmi(Windows Management Instrumentation)の RPM …

nagios snmp ディスク使用率表示スクリプトのカスタマイズ

  [pukiwiki] もともとcheck_snmp_storageを使用していたが、nagiosgraphでグラフを出力させるための perfdataの表示を、nagiosgraph側でパーティシ …

nagios/引数マクロ(macros)

[pukiwiki] nagiosで設定される引数がどこで定義されているのかをちょっと調べてみた。 システム内で使われる変数はマクロとして扱われる。 (言うなればnagiosの環境変数、的な?ちょっと …

nagios​/plugin​/Recurring schedule

  [pukiwiki] *nagios ダウンタイムの定期スケジューリング nagios標準のダウンタイム機能は一回限りのスケジュール設定のみが可能で、 “毎晩03時~05時は非通知&# …

宅麺