mmm_tools配置手冊

目錄
一、文檔申明 
二、mmm_tools介紹 
三、預備知識 
四、環境需求 
五、演示環境 
六、配置mmm_tools.cnf 
七、工具演示 
mmm_clone: 
A、使用mmm_clone完成db2到db1的數據同步,並且完成master-master架構的搭建。 
mmm_backup: 
A、使用scp方法把db1的數據備份到本地的/mmm_backup中 
B、使用ssh-gz方法把db1的數據備份到本地的/mmm_backup中 
C、使用rdiff方法把db2的數據備份到本地的/mmm_backup中 
mmm_restore: 
A、使用scp拷貝模式還原數據庫。 
B、還原rdiff的備份 
八、故障總結 


一、文檔申明
 此文檔並非官方文檔,官方文檔對mmm_tools的介紹介幾乎爲零,此文檔爲本人測試和使用得出的結論,如果文檔中有錯誤的地方,希望多包涵,更希望你能發送郵件([email protected])告訴我哪裏錯了。本文檔只是個人工作經驗總結,由本文檔引起的不良後果本人概不負責。
                                                              作者:andy.feng
      網名:fh.cn
Email:[email protected]
BLOG:http://linuxguest.blog.51cto.com
2011/7/8


二、mmm_tools介紹
 mmm_tools是mysql-mmm軟件的一個附帶工具箱,自帶三個工具。
 mmm_clone //用來克隆一個mysql數據庫到另外的機器,並且自動完成master-master或者master-slave的環境搭建,很好用。
 mmm_backup //用來備份一個mysql數據庫,備份的時候使用了lvm快照技術,所以支持熱備,並且鎖表的時間相當的短,支持三種拷貝的方法,scp,ssh-gz,rdiff,下面會詳細介紹。
 mmm_restare  //還原數據到一個mysql數據庫,並完成master-master或者master-slave的環境搭建,不過還原還是建議手動操作,除非你對此工具很熟悉,能夠熟練使用,這樣才能降低操作帶來的風險。

三、預備知識
mysql-mmm中文手冊:http://linuxguest.blog.51cto.com/195664/578311
mysql-mmm安裝手冊:http://linuxguest.blog.51cto.com/195664/578307
lvm快照技術:http://asram.blog.51cto.com/1442164/313073
使用lvm快照備份mysql:http://linuxguest.blog.51cto.com/195664/585036
如果你對以上知識沒有了解的話,請先閱讀以上資料,並預先搭建好mysql-mmm架構,應爲mmm_tools是依賴mysql-mmm架構工作的。

四、環境需求
一、 搭建好mysql-mmm環境
二、 安裝好mysql數據庫,所有服務器儘量使用相同的mysql版本
三、 mysql數據庫軟件放在lvm的邏輯捲上面(備份需要lvm快照功能),並且存放mysql數據庫的邏輯卷組除了mysql數據庫使用的空間外,還要剩餘1-10G的空間用於創建快照,快照空間大小根據你數據庫的大小和短時間的會改變的數據量大小來定,寧多勿少。
四、 安裝rdiff-backup,rdiff-backup是支持增量備份的一種軟件。在mysql-backup rdiff拷貝方法中會用到。
參考:http://wiki.rdiff-backup.org/wiki/index.php/Installations

五、演示環境
 我會通過展示我的mysql-mmm配置文件來展示我的演示環境。
 數據庫版本:mysql-5.1.40,可以通過mysql-mmm安裝文檔找到下載地址。
 操作系統:RHEL5.4
 mysql-mmm:mysql-mmm-2.2.1
 
 由於是演示環境,所以我只用了兩臺服務器,和mysql-mmm安裝手冊中有一點差別,請大家注意。
IP地址 主機 角色
192.168.199.128 db1 mmm-monitor  mmm-agent
192.168.199.129 db2 mmm-agent
 其他配置參見我的mysql-mmm相關配置文件:
# cat mmm_common.conf
active_master_role      writer
<host default>
        cluster_interface               eth0
        pid_path                                /var/run/mmm_agentd.pid
        bin_path                                /usr/lib/mysql-mmm/
    replication_user        slave
    replication_password    slave
        agent_user                              mmm_agent
        agent_password                         mmm_agent
        mysql_port                              9188
</host>
<host db1>
        ip                                      192.168.199.128
        mode                                    master
        peer                                    db2
</host>
<host db2>
        ip                                      192.168.199.129
        mode                                    master
        peer                                    db1
</host>
<role writer>
        hosts                                   db1, db2
        ips                                     192.168.199.200
        mode                                   exclusive
</role>
<role reader>
        hosts                                   db1, db2
        ips                                     192.168.199.201,192.168.199.202
        mode                                   balanced
</role>

# cat mmm_mon.conf
include mmm_common.conf

<monitor>
        ip                                      192.168.199.128
        pid_path                                /var/run/mmm_mond.pid
        bin_path                                /usr/lib/mysql-mmm/
        status_path                             /var/lib/misc/mmm_mond.status
        ping_ips                                192.168.199.128,192.168.199.129
</monitor>

<host default>
        monitor_user                    mmm_monitor
        monitor_password                mmm_monitor
</host>

debug 0

六、配置mmm_tools.cnf
每個服務器的mmm_tools.cnf可以不一樣,具體配置根據本級環境而定。
配置如下:
include mmm_agent.conf //導入agent和common的配置
default_copy_method                     scp  //默認選擇copy的方法,從下面定義的中間選擇一個(scp,rdiff,ssh-gz),稍後我們挨個測試。
clone_dirs                              var  //邏輯卷中需要備份的目錄,clone的源目錄,restore的目標目錄,使用邏輯卷掛載的相對路徑。比如我的邏輯卷掛載到/usr/local/mysql/這個目錄,那麼我們要備份的數據庫文件放在/usr/local/mysql/var/這個目錄中,這裏我們就寫var就行了。
<host default>
    ssh_user                    root //ssh使用的用戶名,如果有證書,就可以直接拷貝,沒有製作證書就會交互的讓你輸入密碼。
    lvm_snapshot_size           1G  //快照的撤銷空間大小,也就是lvcreate -L參數的大小,具體請研究lvcreate命令,根據你的實際情況來填寫此項。
    lvm_logical_volume          lvmdb //前主機環境要備份文件所在的邏輯卷
    lvm_volume_group            myvg //前主機環境要備份文件所在的邏輯卷組
    lvm_mount_dir                       /mmm_snapshot //創建lvm快照後的臨時掛載點,可以隨意填寫,填寫後,自己創建此目錄
    lvm_mount_opts                      -o rw //掛載lvm快照的參數,修改成這樣就行了,默認的參數存在問題。

        tools_user                              mmm_tools //mmm_tools使用的一個用戶,要求有super,replication client,reload權限。
        tools_password                          mmm_tools //mmm_tools用戶的密碼.

        backup_dir                              /mmm_backup //mmm_backup備份出的文件保存路徑,mmm_restore還原時使用的源數據目錄,如果此路徑中已經有備份存在的話,mmm_backup時就會要求你重新寫一個路徑,rdiff拷貝方式可以一直把備份存在一個目錄裏,填寫後創建此目錄。
        restore_dir                             /mysql //使用mmm_restore命令,數據會被還原到此目錄,本來這個目錄應該寫/usr/local/mysql/,但是爲了避免誤操作,還原覆蓋了有用數據,所以就寫到其他目錄。
</host>

<copy_method scp> // default_copy_method調用的拷貝的方法,除了這裏配置默認的,在使用命令的時候可以單獨指定。scp方法就是普通的scp命令,如果你ssh端口修改過的話 –P後面寫上你修改過的端口就行了。
    backup_command scp -P22 -c blowfish -r %SSH_USER%@%IP%:%SNAPSHOT%/%CLONE_DIR% %DEST_DIR%/
    restore_command cp -axv %BACKUP_DIR%/* %DEST_DIR%/
        true_copy 1
</copy_method>

<copy_method rdiff> //如果想使用這個拷貝方法,需要安裝rdiff-backup工具,請參考上面給出的wiki地址安裝和使用。
        backup_command rdiff-backup --ssh-no-compression -v 5 !--include %SNAPSHOT%/%CLONE_DIR%! --exclude %SNAPSHOT% %SSH_USER%@%IP%::%SNAPSHOT%/ %DEST_DIR%/
        restore_command rdiff-backup --force -v 5 -r %VERSION% %BACKUP_DIR% %DEST_DIR%/.mmm_restore; cp -axvl --remove-destination %DEST_DIR%/.mmm_restore/*  %DEST_DIR%/; rm -r
%DEST_DIR%/.mmm_restore/
        incremental_command rdiff-backup --parsable-output -l %BACKUP_DIR%
        single_run 1
        incremental 1
</copy_method>

<copy_method ssh-gz> //使用gzip壓縮後在使用scp拷貝
        backup_command ssh -P35555 -c blowfish %SSH_USER%@%IP% "cd '%SNAPSHOT%'; tar cv !'%CLONE_DIR%'!" | gzip > %DEST_DIR%/backup.tar.gz
        restore_command cd %DEST_DIR%; tar xzfv %BACKUP_DIR%/backup.tar.gz
        single_run 1
</copy_method>

至此mmm-tools.cnf配置文件講解完畢。

七、工具演示
mmm_clone:
 用法:
 Usage: /usr/sbin/mmm_clone [--config <config file>] --host <host> --clone-mode <mode> [--copy-method <copy method>] [--dest-dir <dir>]
Where:
  host       : db1 | db2
  clone-mode : master-master | master-slave | slave-slave
  copy-method: scp (default: ssh-gz)
  dest-dir   : directory where data should be cloned to
 要求:
1、mysql-mmm已經安裝好,並啓動了。
 2、db1和db2的數據庫軟件已經安裝好,包括my.cnf已經配置好(具體配置和注意事項請參照mysql-mmm安裝手冊)。
 3、將要使用的數據導入到db2,並且把db1和db2需要的授權的用戶都在db2上建立好(建立的時候注意可以訪問的主機的限制)。
 完成以上任務後,啓動db2。把db1的/usr/local/mysql/var/目錄清空。
 db1:
 # pwd && ls
/usr/local/mysql/var
# mmm_control show
  db1(192.168.199.128) master/HARD_OFFLINE. Roles:
  db2(192.168.199.129) master/ONLINE. Roles: reader(192.168.199.201), reader(192.168.199.202), writer(192.168.199.200)
A、現在我們使用mmm_clone完成db2到db1的數據同步,並且完成master-master架構的搭建。
db1:
# mmm_clone --host db2  --copy-method scp  --clone-mode master-master --dest-dir /usr/local/mysql/
INFO: Checking destination directory '/usr/local/mysql/'...
INFO: Directory is ok
 Source host                    : db2
 Destination dir                : /usr/local/mysql/
 Dirs to clone                  : var
 Clone mode                     : master-master
 Copy method                    : scp
 Replication peer               : db2
 Setup master-master replication: yes
 Dry run                        : no
WARN: MySQL is not running now, skipping shutdown ...
INFO: Verifying ssh connection to remote host '[email protected]' (command: ssh  -p 22 [email protected] date)...
[email protected]'s password:
2011年 07月 09日 星期六 22:01:13 CST
INFO: OK: SSH connection works fine!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/create_snapshot
[email protected]'s password:
File descriptor 4 (socket:[173814]) leaked on lvcreate invocation. Parent PID 11003: perl
  Logical volume "mmm_snapshot" created
OK: Snapshot created!
INFO: Copying 'var' from snapshot on host 'db2' with copy method 'scp'
INFO: Executing command scp -P22 -c blowfish -r [email protected]:/mmm_snapshot/var /usr/local/mysql//
[email protected]'s password:
host.frm                                                                                                                 100% 9510     9.3KB/s   00:00   
user.frm                                                                                                                 100%   10KB  10.2KB/s   00:00   
procs_priv.frm                                                                                                           100% 8875     8.7KB/s   00:00   
time_zone.MYD                                                                                                            100%    0     0.0KB/s   00:00   
省略。。。。。。。。。。。。。。。。   
rdiff.MYD                                                                                                                100%   20     0.0KB/s   00:00   
rdiff.frm                                                                                                                100% 8590     8.4KB/s   00:00   
t.MYI                                                                                                                    100% 2048     2.0KB/s   00:00   
mysql-bin.000002                                                                                                         100%  125     0.1KB/s   00:00   
mysql-bin.000003                                                                                                         100%  724     0.7KB/s   00:00   
mysql-bin.000001                                                                                                         100%  149     0.2KB/s   00:00   
mysql-bin.index                                                                                                          100%   95     0.1KB/s   00:00   
test2.example.com.pid                                                                                                    100%    5     0.0KB/s   00:00   
mysql-bin.000005                                                                                                         100%  106     0.1KB/s   00:00   
mysql-bin.000004                                                                                                         100%  350     0.3KB/s   00:00   
INFO: Copied directory var!
INFO: Copying '_mmm' from snapshot on host 'db2' with copy method 'scp'
INFO: Executing command scp -P22 -c blowfish -r [email protected]:/mmm_snapshot/_mmm /usr/local/mysql//
[email protected]'s password:
status.txt                                                                                                               100%  315     0.3KB/s   00:00   
my.cnf                                                                                                                   100% 5569     5.4KB/s   00:00   
INFO: Copied directory _mmm!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/remove_snapshot
[email protected]'s password:
  Logical volume "mmm_snapshot" successfully removed
OK: Snapshot removed!
INFO: Cleaning dump from master.info and binary logs...
INFO: Deleting master binary logs: mysql-bin.*
removed `/usr/local/mysql/var/mysql-bin.000001'
removed `/usr/local/mysql/var/mysql-bin.index'
removed `/usr/local/mysql/var/mysql-bin.000002'
removed `/usr/local/mysql/var/mysql-bin.000004'
removed `/usr/local/mysql/var/mysql-bin.000005'
removed `/usr/local/mysql/var/mysql-bin.000003'
INFO: Deleting .info and .pid  files...
removed `/usr/local/mysql/var/test2.example.com.pid'
INFO: Changing permissions on mysql data dir...
INFO: MySQL is not running. Going to start it...
Starting MySQL...                                          [  OK  ]
INFO: MySQL has been started!
INFO: Changing master of host db1 to 192.168.199.129 ...
INFO: Successfully changed master.
INFO: Changing master of host db2 to 192.168.199.128 ...
INFO: Successfully changed master.
INFO: Clone operation finished!

 

檢查結果:
[root@andy var]# mmm_control show
  db1(192.168.199.128) master/AWAITING_RECOVERY. Roles:
  db2(192.168.199.129) master/ONLINE. Roles: reader(192.168.199.201), reader(192.168.199.202), writer(192.168.199.200)

[root@andy var]# mmm_control set_online db1
OK: State of 'db1' changed to ONLINE. Now you can wait some time and check its new roles!
[root@andy var]# mmm_control show
  db1(192.168.199.128) master/ONLINE. Roles: reader(192.168.199.202)
  db2(192.168.199.129) master/ONLINE. Roles: reader(192.168.199.201), writer(192.168.199.200)

[root@andy var]# mmm_control checks all
db2  ping         [last change: 2011/07/03 02:10:35]  OK
db2  mysql        [last change: 2011/07/09 21:48:05]  OK
db2  rep_threads  [last change: 2011/07/09 22:01:22]  OK
db2  rep_backlog  [last change: 2011/07/09 22:01:22]  OK: Backlog is null
db1  ping         [last change: 2011/07/02 18:27:51]  OK
db1  mysql        [last change: 2011/07/09 22:01:22]  OK
db1  rep_threads  [last change: 2011/07/09 22:01:22]  OK
db1  rep_backlog  [last change: 2011/07/02 18:27:51]  OK: Backlog is null
當然,你還可以登陸到每臺機器,使用 show slave status\G來詳細檢查。
呵呵,是不是很爽呢。
mmm_backup:
 基於上面搭建的環境,我們來演示三種copy方法。
 用法:
 Usage: /usr/sbin/mmm_backup [--config <config file>] --host <host> [--copy-method <copy method>] [--dest-dir <dir>]
Where:
  host       : db1 | db2
  copy-method: rdiff | scp | ssh-gz (default: ssh-gz)
  dest-dir   : directory where data should be backed up to
A、使用scp方法把db1的數據備份到本地的/mmm_backup中。
[root@andy ~]# mmm_backup --host db1 --copy-method scp --dest-dir /mmm_backup/
INFO: Checking local destination directory '/mmm_backup/'...
INFO: Directory is ok
INFO: Verifying ssh connection to remote host '[email protected]' (command: ssh  -p 22 [email protected] date)...
[email protected]'s password:
Sat Jul  9 22:10:05 CST 2011
INFO: OK: SSH connection works fine!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/create_snapshot
[email protected]'s password:
File descriptor 4 (socket:[376105]) leaked on lvcreate invocation. Parent PID 21921: perl
  Logical volume "mmm_snapshot" created
OK: Snapshot created!
INFO: Copying 'var' from snapshot on host 'db1' with copy method 'scp'
INFO: Executing command scp -P22 -c blowfish -r [email protected]:/mmm_snapshot/var /mmm_backup//
[email protected]'s password:
andy-relay-bin.000002                                                                                                    100%  251     0.3KB/s   00:00   
master.info                                                                                                              100%   69     0.1KB/s   00:00   
mysql-bin.000001                                                                                                         100%  106     0.1KB/s   00:01   
andy.example.com.pid                                                                                                     100%    6     0.0KB/s   00:00   
t.MYD                                                                                                                    100%  120     0.1KB/s   00:00   
rdiff.MYI                                                                                                                100% 1024     1.0KB/s   00:00   
rdiff.frm                                                                                                                100% 8590     8.4KB/s   00:00   
t.frm                                                                                                                    100% 8586     8.4KB/s   00:00   
t.MYI                                                                                                                    100% 2048     2.0KB/s   00:00   
省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
columns_priv.MYI                                                                                                         100% 4096     4.0KB/s   00:00   
general_log.frm                                                                                                          100% 8776     8.6KB/s   00:00   
slow_log.CSM                                                                                                             100%   35     0.0KB/s   00:00   
ndb_binlog_index.MYI                                                                                                     100% 1024     1.0KB/s   00:00   
time_zone_leap_second.MYI                                                                                                100% 1024     1.0KB/s   00:00   
relay-log.info                                                                                                           100%   49     0.1KB/s   00:00   
andy-relay-bin.index                                                                                                     100%   48     0.1KB/s   00:00   
INFO: Copied directory var!
INFO: Copying '_mmm' from snapshot on host 'db1' with copy method 'scp'
INFO: Executing command scp -P22 -c blowfish -r [email protected]:/mmm_snapshot/_mmm /mmm_backup//
[email protected]'s password:
status.txt                                                                                                               100% 2344     2.3KB/s   00:00   
my.cnf                                                                                                                   100% 5570     5.4KB/s   00:00   
copy_method.txt                                                                                                          100%    3     0.0KB/s   00:00   
INFO: Copied directory _mmm!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/remove_snapshot
[email protected]'s password:
  Logical volume "mmm_snapshot" successfully removed
OK: Snapshot removed!
[root@andy ~]# cd /mmm_backup/
[root@andy mmm_backup]# ls
_mmm  var
[root@andy mmm_backup]# ls /mmm_backup/var/
andy.example.com.pid   andy-relay-bin.000002  master.info  mysql-bin.000001  relay-log.info
andy-relay-bin.000001  andy-relay-bin.index   mysql        mysql-bin.index   test

B、使用ssh-gz方法把db1的數據備份到本地的/mmm_backup中。
注意,此時/mmm_backup中已經存在一個備份了,所以在備份到這個目錄會不成功,我們可以重新指定一個目錄,或者將此目錄中備份刪掉。
db1:
# cd /mmm_backup/
[root@andy mmm_backup]# ls
_mmm  var
[root@andy mmm_backup]# rm -rf *
[root@andy mmm_backup]# mmm_backup --host db1 --copy-method ssh-gz --dest-dir /mmm_backup/
INFO: Checking local destination directory '/mmm_backup/'...
INFO: Directory is ok
INFO: Verifying ssh connection to remote host '[email protected]' (command: ssh  -p 22 [email protected] date)...
[email protected]'s password:
Sat Jul  9 22:31:09 CST 2011
INFO: OK: SSH connection works fine!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/create_snapshot
[email protected]'s password:
File descriptor 4 (socket:[387068]) leaked on lvcreate invocation. Parent PID 23250: perl
  Logical volume "mmm_snapshot" created
OK: Snapshot created!
INFO: Copying files from snapshot on host 'db1' with copy method 'ssh-gz'
INFO: Executing command ssh -P22 -c blowfish [email protected] "cd '/mmm_snapshot'; tar cv  'var'" | gzip > /mmm_backup//backup.tar.gz
[email protected]'s password:
var/
var/andy-relay-bin.000002
var/master.info
var/mysql-bin.000001
var/andy.example.com.pid
var/test/
省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
var/mysql/ndb_binlog_index.MYI
var/mysql/time_zone_leap_second.MYI
var/relay-log.info
var/andy-relay-bin.index
INFO: Copied directories 'var' from host 'db1'!
INFO: Copying '_mmm' from snapshot on host 'db1' with copy method 'scp'
INFO: Executing command scp -P22 -c blowfish -r [email protected]:/mmm_snapshot/_mmm /mmm_backup//
[email protected]'s password:
status.txt                                                                                                               100% 2344     2.3KB/s   00:00   
my.cnf                                                                                                                   100% 5570     5.4KB/s   00:00   
copy_method.txt                                                                                                          100%    3     0.0KB/s   00:00   
INFO: Copied directory _mmm!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/remove_snapshot
[email protected]'s password:
  Logical volume "mmm_snapshot" successfully removed
OK: Snapshot removed!
[root@andy mmm_backup]# ls
backup.tar.gz  _mmm
這種備份優勢相當於第一種來說,傳說的數據量要少很多,備份的數據佔用空間也會少很多,scp方法佔用的空間會比ssh-gz壓縮後多6倍左右。

C、使用rdiff方法把db2的數據備份到本地的/mmm_backup中。
使用詞拷貝方法,記得要先安裝rdiff-backup工具。
db1:
[root@andy mmm_backup]# mmm_backup --host db2 --copy-method rdiff --dest-dir /mmm_backup/      
INFO: Checking local destination directory '/mmm_backup/'...
INFO: Directory is ok
INFO: Verifying ssh connection to remote host '[email protected]' (command: ssh  -p 22 [email protected] date)...
[email protected]'s password:
2011年 07月 09日 星期六 22:38:31 CST
INFO: OK: SSH connection works fine!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/create_snapshot
[email protected]'s password:
File descriptor 4 (socket:[194118]) leaked on lvcreate invocation. Parent PID 15146: perl
  Logical volume "mmm_snapshot" created
OK: Snapshot created!
INFO: Copying files from snapshot on host 'db2' with copy method 'rdiff'
INFO: Executing command rdiff-backup --ssh-no-compression -v 5  --include /mmm_snapshot/var --exclude /mmm_snapshot [email protected]::/mmm_snapshot/ /mmm_backup//
Using rdiff-backup version 1.2.8
Executing ssh [email protected] rdiff-backup --server
[email protected]'s password:
Unable to import module xattr.
Extended attributes not supported on filesystem at /mmm_snapshot
Unable to import module posix1e from pylibacl package.
POSIX ACLs not supported on filesystem at /mmm_snapshot
Unable to import win32security module. Windows ACLs
not supported by filesystem at /mmm_snapshot
escape_dos_devices not required by filesystem at /mmm_snapshot
-----------------------------------------------------------------
Detected abilities for source (read only) file system:
  Access control lists                         Off
  Extended attributes                          Off
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
Unable to import module xattr.
Extended attributes not supported on filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
Unable to import module posix1e from pylibacl package.
POSIX ACLs not supported on filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
Unable to import win32security module. Windows ACLs
not supported by filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
escape_dos_devices not required by filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
-----------------------------------------------------------------
Detected abilities for destination (read/write) file system:
  Ownership changing                           On
  Hard linking                                 On
  fsync() directories                          On
  Directory inc permissions                    On
  High-bit permissions                         On
  Symlink permissions                          Off
  Extended filenames                           On
  Windows reserved filenames                   Off
  Access control lists                         Off
  Extended attributes                          Off
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
Backup: must_escape_dos_devices = 0
Starting mirror /mmm_snapshot to /mmm_backup
Processing changed file .
Processing changed file var
Processing changed file var/master.info
Processing changed file var/mysql
Processing changed file var/mysql/columns_priv.MYD
省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Processing changed file var/test2.example.com.pid
INFO: Copied directories 'var' from host 'db2'!
INFO: Copying '_mmm' from snapshot on host 'db2' with copy method 'scp'
INFO: Executing command scp -P22 -c blowfish -r [email protected]:/mmm_snapshot/_mmm /mmm_backup//
[email protected]'s password:
status.txt                                                                                                               100% 2345     2.3KB/s   00:00   
my.cnf                                                                                                                   100% 5569     5.4KB/s   00:00   
INFO: Copied directory _mmm!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/remove_snapshot
[email protected]'s password:
  Logical volume "mmm_snapshot" successfully removed
OK: Snapshot removed!

在db2上更新一下test.t表,創建t1表,然後再備份一次。
mysql> insert into t(name) values ('example');
mysql> create table t1  like t;

[root@andy mmm_backup]# mmm_backup --host db2 --copy-method rdiff --dest-dir /mmm_backup/
INFO: Checking local destination directory '/mmm_backup/'...
INFO: Directory is ok
INFO: Verifying ssh connection to remote host '[email protected]' (command: ssh  -p 22 [email protected] date)...
[email protected]'s password:
2011年 07月 09日 星期六 22:43:47 CST
INFO: OK: SSH connection works fine!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/create_snapshot
[email protected]'s password:
File descriptor 4 (socket:[197475]) leaked on lvcreate invocation. Parent PID 15945: perl
  Logical volume "mmm_snapshot" created
OK: Snapshot created!
INFO: Copying files from snapshot on host 'db2' with copy method 'rdiff'
INFO: Executing command rdiff-backup --ssh-no-compression -v 5  --include /mmm_snapshot/var --exclude /mmm_snapshot [email protected]::/mmm_snapshot/ /mmm_backup//
Using rdiff-backup version 1.2.8
Executing ssh [email protected] rdiff-backup --server
[email protected]'s password:
Unable to import module xattr.
Extended attributes not supported on filesystem at /mmm_snapshot
Unable to import module posix1e from pylibacl package.
POSIX ACLs not supported on filesystem at /mmm_snapshot
Unable to import win32security module. Windows ACLs
not supported by filesystem at /mmm_snapshot
escape_dos_devices not required by filesystem at /mmm_snapshot
-----------------------------------------------------------------
Detected abilities for source (read only) file system:
  Access control lists                         Off
  Extended attributes                          Off
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
Unable to import module xattr.
Extended attributes not supported on filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
Unable to import module posix1e from pylibacl package.
POSIX ACLs not supported on filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
Unable to import win32security module. Windows ACLs
not supported by filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
escape_dos_devices not required by filesystem at /mmm_backup/rdiff-backup-data/rdiff-backup.tmp.0
-----------------------------------------------------------------
Detected abilities for destination (read/write) file system:
  Ownership changing                           On
  Hard linking                                 On
  fsync() directories                          On
  Directory inc permissions                    On
  High-bit permissions                         On
  Symlink permissions                          Off
  Extended filenames                           On
  Windows reserved filenames                   Off
  Access control lists                         Off
  Extended attributes                          Off
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
Backup: must_escape_dos_devices = 0
Starting increment operation /mmm_snapshot to /mmm_backup
Processing changed file .
Incrementing mirror file /mmm_backup
Processing changed file var
Incrementing mirror file /mmm_backup/var
Processing changed file var/master.info
Incrementing mirror file /mmm_backup/var/master.info
Processing changed file var/mysql-bin.000005
Incrementing mirror file /mmm_backup/var/mysql-bin.000005
Processing changed file var/relay-log.info
Incrementing mirror file /mmm_backup/var/relay-log.info
Processing changed file var/test
Incrementing mirror file /mmm_backup/var/test
Processing changed file var/test/t.MYD
Incrementing mirror file /mmm_backup/var/test/t.MYD
Processing changed file var/test/t.MYI
Incrementing mirror file /mmm_backup/var/test/t.MYI
Processing changed file var/test/t1.MYD
Incrementing mirror file /mmm_backup/var/test/t1.MYD
Processing changed file var/test/t1.MYI
Incrementing mirror file /mmm_backup/var/test/t1.MYI
Processing changed file var/test/t1.frm
Incrementing mirror file /mmm_backup/var/test/t1.frm
Processing changed file var/test2-relay-bin.000002
Incrementing mirror file /mmm_backup/var/test2-relay-bin.000002
INFO: Copied directories 'var' from host 'db2'!
INFO: Copying '_mmm' from snapshot on host 'db2' with copy method 'scp'
INFO: Executing command scp -P22 -c blowfish -r [email protected]:/mmm_snapshot/_mmm /mmm_backup//
[email protected]'s password:
status.txt                                                                                                               100% 2345     2.3KB/s   00:00   
my.cnf                                                                                                                   100% 5569     5.4KB/s   00:00   
INFO: Copied directory _mmm!
INFO: ssh  -p 22 [email protected] /usr/lib/mysql-mmm//tools/remove_snapshot
[email protected]'s password:
  Logical volume "mmm_snapshot" successfully removed
OK: Snapshot removed!
從以上內容來看,rdiff-backup是以文件爲單位來做增量備份的,對於那些很大的表,這種增量備份就沒太大意義了。
mmm_restore:
還原也分三種拷貝模式,scp和ssh-gz差不多,rdiff屬於增量備份,可以選擇還原的版本號。這裏我們就只演示scp和rdiff兩種還原。
用法:
Usage: /usr/sbin/mmm_restore [--config <config file>] [--mode <mode>] [--version <version | list>] [--src-dir <dir>] [--dest-dir <dir>] [--dry-run]
Where:
  src-dir : directory where backup resides
  dest-dir: directory where backup should be restored to
  mode    : data-only, single-single, slave-single, master-single, master-slave, slave-slave
  version :
    - when run with 'list' parameter, displays available versions of incremental backups
    - if version is specified, tries to restore backup for specified version
  dry-run : check everything and exit without any changes
從上面可以看出,mmm_restore使用的—src-dir和—dest-dir,而不是—host。
A、使用scp拷貝模式還原數據庫。
現在我們模仿db1數據庫文件丟失,需要還原數據的場景。首先手工刪除test數據文件。
db1:
[root@andy var]# cd /usr/local/mysql/var/ && rm -rf test/
[root@andy var]# ls
andy.example.com.pid   andy-relay-bin.000002  master.info  mysql-bin.000001  relay-log.info
andy-relay-bin.000001  andy-relay-bin.index   mysql        mysql-bin.index
還原數據:
[root@andy var]# mmm_restore
INFO: Checking restore source directory '/mmm_backup'...
INFO: Directory is ok
 Source dir            : /mmm_backup
 Destination dir       : /mysql
 Dirs to restore       : var
 Restore mode          : single-single
 Skip mysqld operations: no
 Dry run               : no
WARN: MySQL is not running now, skipping shutdown ...
INFO: Checking destination directory '/mysql'...
INFO: Directory is ok
INFO: Executing command cp -axv /mmm_backup/* /mysql/
`/mmm_backup/_mmm' -> `/mysql/_mmm'
`/mmm_backup/_mmm/copy_method.txt' -> `/mysql/_mmm/copy_method.txt'
`/mmm_backup/_mmm/status.txt' -> `/mysql/_mmm/status.txt'
`/mmm_backup/_mmm/my.cnf' -> `/mysql/_mmm/my.cnf'
`/mmm_backup/var/relay-log.info' -> `/mysql/var/relay-log.info'
`/mmm_backup/var/andy-relay-bin.000001' -> `/mysql/var/andy-relay-bin.000001'
`/mmm_backup/var/andy.example.com.pid' -> `/mysql/var/andy.example.com.pid'
`/mmm_backup/var/mysql/time_zone_transition_type.frm' -> `/mysql/var/mysql/time_zone_transition_type.frm'
省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
`/mmm_backup/var/test/t.MYD' -> `/mysql/var/test/t.MYD'
`/mmm_backup/var/master.info' -> `/mysql/var/master.info'
`/mmm_backup/var/andy-relay-bin.index' -> `/mysql/var/andy-relay-bin.index'
`/mmm_backup/var/mysql-bin.000001' -> `/mysql/var/mysql-bin.000001'
INFO: Restored backup from '/mmm_backup' to '/mysql'
INFO: Cleaning dump from master.info and binary logs...
INFO: Deleting master binary logs: mysql-bin.*
removed `/mysql/var/mysql-bin.index'
removed `/mysql/var/mysql-bin.000001'
INFO: Deleting relay binary logs: andy-relay-bin.*
removed `/mysql/var/andy-relay-bin.000001'
removed `/mysql/var/andy-relay-bin.000002'
removed `/mysql/var/andy-relay-bin.index'
INFO: Deleting .info and .pid  files...
removed `/mysql/var/master.info'
removed `/mysql/var/relay-log.info'
removed `/mysql/var/andy.example.com.pid'
INFO: Changing permissions on mysql data dir...
INFO: MySQL is not running. Going to start it...
Starting MySQL                                             [  OK  ]
INFO: MySQL has been started!
INFO: Skipping replication setup because destination configuration is 'single'
INFO: Restore operation finished!
[root@andy var]# ls /mysql
_mmm  var

這裏並沒有演示完整還原,因爲還原或導致master-master複製失敗,還原完成,db1已經自動把master轉向db2,但是db2對db1的複製失敗了,應爲db1的bin-log發生了變化,需要手工恢復master-master複製。
如果真實情況master數據丟失需要還原的話,就需要先resote到master,然後再mmm_clone生成複製架構。如果只是slave損壞,沒必要還原,直接mmm_clone過來就可以了。

B、還原rdiff的備份
[root@andy ~]# mmm_restore  --mode master-slave --version list --src-dir /mmm_backup/ --dest-dir /usr/local/mysql/ --dry-run                               INFO: Checking restore source directory '/mmm_backup/'...
INFO: Directory is ok
Following backup versions are available:
     Version | Date
-------------|---------------------------
  1310222305 | Sat Jul  9 22:38:25 2011
  1310222616 | Sat Jul  9 22:43:36 2011

[root@andy ~]# mmm_restore  --mode master-slave --version 1310222616 --src-dir /mmm_backup/ --dest-dir /usr/local/mysql/ --dry-run   
INFO: Checking restore source directory '/mmm_backup/'...
INFO: Directory is ok
 Source dir            : /mmm_backup/
 Destination dir       : /usr/local/mysql/
 Dirs to restore       : var
 Restore mode          : master-slave
 Incremental version   : 1310222616
 Replication peer      : db2
 Skip mysqld operations: no
 Dry run               : yes

--version //選擇version編號或者使用—list顯示可用的編號。
--dry-run //測試是否可以運行,不真正運行。
使用還原前關掉mysql數據庫,貌似mmm_tools存在一個bug,關於還原前和clone前關閉數據庫的命令。
[root@andy var]# mmm_restore  --mode master-slave --version 1310222616 --src-dir /mmm_backup/ --dest-dir /usr/local/mysql/
INFO: Checking restore source directory '/mmm_backup/'...
INFO: Directory is ok
 Source dir            : /mmm_backup/
 Destination dir       : /usr/local/mysql/
 Dirs to restore       : var
 Restore mode          : master-slave
 Incremental version   : 1310222616
 Replication peer      : db2
 Skip mysqld operations: no
 Dry run               : no
WARN: MySQL is not running now, skipping shutdown ...
INFO: Checking destination directory '/usr/local/mysql/'...
INFO: Directory is ok
INFO: Executing command rdiff-backup --force -v 5 -r 1310222616 /mmm_backup/ /usr/local/mysql//.mmm_restore; cp -axvl --remove-destination /usr/local/mysql//.mmm_restore/*  /usr/local/mysql//; rm -r /usr/local/mysql//.mmm_restore/
Using rdiff-backup version 1.2.8
Unable to import module xattr.
Extended attributes not supported on filesystem at /mmm_backup/rdiff-backup-data
Unable to import module posix1e from pylibacl package.
POSIX ACLs not supported on filesystem at /mmm_backup/rdiff-backup-data
Unable to import win32security module. Windows ACLs
not supported by filesystem at /mmm_backup/rdiff-backup-data
escape_dos_devices not required by filesystem at /mmm_backup/rdiff-backup-data
-----------------------------------------------------------------
Detected abilities for rdiff-backup repository (read only) file system:
  Access control lists                         Off
  Extended attributes                          Off
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
Unable to import module xattr.
Extended attributes not supported on filesystem at /usr/local/mysql/.mmm_restore/rdiff-backup.tmp.0
Unable to import module posix1e from pylibacl package.
POSIX ACLs not supported on filesystem at /usr/local/mysql/.mmm_restore/rdiff-backup.tmp.0
Unable to import win32security module. Windows ACLs
not supported by filesystem at /usr/local/mysql/.mmm_restore/rdiff-backup.tmp.0
escape_dos_devices not required by filesystem at /usr/local/mysql/.mmm_restore/rdiff-backup.tmp.0
-----------------------------------------------------------------
Detected abilities for restore target (read/write) file system:
  Ownership changing                           On
  Hard linking                                 On
  fsync() directories                          On
  Directory inc permissions                    On
  High-bit permissions                         On
  Symlink permissions                          Off
  Extended filenames                           On
  Windows reserved filenames                   Off
  Access control lists                         Off
  Extended attributes                          Off
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
Restore: must_escape_dos_devices = 0
Starting restore of /mmm_backup to /usr/local/mysql/.mmm_restore as it was as of Sat Jul  9 22:43:36 2011.
Processing changed file .
Processing changed file var
Processing changed file var/master.info
Processing changed file var/relay-log.info
省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
`/usr/local/mysql//.mmm_restore/var/mysql-bin.000003' -> `/usr/local/mysql/var/mysql-bin.000003'
INFO: Restored backup version '1310222616' from '/mmm_backup/' to '/usr/local/mysql/'
INFO: Cleaning dump from master.info and binary logs...
INFO: Deleting master binary logs: mysql-bin.*
removed `/usr/local/mysql/var/mysql-bin.000001'
removed `/usr/local/mysql/var/mysql-bin.index'
removed `/usr/local/mysql/var/mysql-bin.000002'
removed `/usr/local/mysql/var/mysql-bin.000004'
removed `/usr/local/mysql/var/mysql-bin.000005'
removed `/usr/local/mysql/var/mysql-bin.000003'
INFO: Deleting relay binary logs: test2-relay-bin.*
removed `/usr/local/mysql/var/test2-relay-bin.000001'
removed `/usr/local/mysql/var/test2-relay-bin.index'
removed `/usr/local/mysql/var/test2-relay-bin.000002'
INFO: Deleting .info and .pid  files...
removed `/usr/local/mysql/var/master.info'
removed `/usr/local/mysql/var/relay-log.info'
removed `/usr/local/mysql/var/test2.example.com.pid'
INFO: Changing permissions on mysql data dir...
INFO: MySQL is not running. Going to start it...
Starting MySQL..                                           [  OK  ]
INFO: MySQL has been started!
INFO: Changing master of host db1 to 192.168.199.129 ...
INFO: Successfully changed master.
INFO: Restore operation finished!
還原完成,db1已經自動把master轉向db2,但是db2對db1的複製失敗了,應爲db1的bin-log發生了變化,這個只有手工處理。
八、故障總結
 1、如果當命令執行到一半而由於配置錯誤退出時,快照已經生成,但是命令未執行完,導致快照沒有刪除,需要自己使用lvremove –f 快照名 刪除快照。
 2、注意mmm_tools.cnf要針對所在主機環境配置,不是所有都一樣。
 3、生產環境下,備份好以後,需要轉移做測試,看備份是否可以用。還原最好手工操作,避免誤傷。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章