CentOS5.5/Amanda

Last-modified: 2011-03-08 (火) 14:28:24
最終更新:2011-03-08 (火) 14:28:24
アクセス数(合計):?
利用者; ? アクセス数(本日):? アクセス数(昨日):?

バックアップシステム Amanda

ネットワークに接続された複数台のクライアントのバックアップを、自動的に行うためバックアップシステムAmandaを導入する。


Amandaはオープンソースで提供されており、Unix系OSで広く使用されている。
特徴として、テープバックアップとハードディスクバックアップの両方をサポートしており、リカバーも簡単という特徴がある。

日々のバックアップを管理することにより、ハード故障時に備えたフルバックアップはもとより、人的ミス等による誤消去にも対応できるようにする。


目的

ネットワークに接続された複数台のサーバのバックアップを自動的に行う。
今回は、
クライアントサーバの /etc エリアおよび amandaサーバの /etc エリアのバックアップを構築する。

構築条件

構築機器

作成環境

OS    CentOS 5.5 64bit版

サーバ作成条件

バックアップサーバサーバIP192.168.0.10/24
ホスト名amandaServer
user   fugafuga
userpasswdfugafugapass
クライアントサーバIP192.168.0.20/24
ホスト名hogehogeServer
user   hogehoge
userpasswdhogehogepass

手順記入ルール

  • コマンド行頭記号で 「$」はユーザ権限 「#」はスーパーユーザー権限 を表示
  • コマンドが長くなる場合は、行末に「\」を記述し複数行に記述。

ファイル入手

サイト

今回インストールしたファイル

★CentOSに収録されているアプリを使用

amanda.i386                            2.5.0p2-8.el5
amanda.x86_64                          2.5.0p2-8.el5
amanda-client.x86_64                   2.5.0p2-8.el5
amanda-server.x86_64                   2.5.0p2-8.el5

前準備

  1. CentOSインストール 実施
  2. yumリポジトリ設定 実施

クライアント構築

インストール

【Telnet】

  • rootでログイン
$ su
パスワード:

(1)インストール

  • インストール
# yum install amanda amanda-client

   :

Complete!

Xinit.d設定

(1)xinetd経由起動登録

【telnet】

  • 確認
# chkconfig --list | grep am
        amanda:         off
  • 設定
# vi /etc/xinetd.d/amanda
  • 変更
           disable                 = yes
          ↓
           disable                 = no
  • 初期設定
# /etc/init.d/xinetd restart
xinetd を停止中:                                           [  OK  ]
xinetd を起動中:                                           [  OK  ]
  • 確認
# chkconfig --list | grep am
        amanda:         on

(2)hosts登録

  • hosts登録
# vi /etc/hosts
  • ローカルホストに設定確認
    127.0.0.1               hogehogeServer localhost.localdomain localhost
  • 最終行に追加
    192.168.0.10           amandaServer

(3)amandahosts登録

  • amandahosts登録
# vi /var/lib/amanda/.amandahosts
  • 最終行に追加
    amandaServer amanda 

バックアップサーバ構築

インストール

【Telnet】

  • rootでログイン
$ su
パスワード:

(1)インストール

  • インストール
# yum install amanda amanda-server amanda-client

   :

Complete!

(2)crontabインストール

  • インストール(crontab実行)
# yum install vixie-cron
  • 起動
# /etc/rc.d/init.d/crond start
crond を起動中:                                            [  OK  ]
  • 常時起動登録
# chkconfig crond on
  • 確認
# chkconfig --list crond
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off

Xinit.d設定

(1)xinetd経由起動登録

【telnet】

  • 確認
# chkconfig --list | grep am
        amanda:         off
        amandaidx:      off
        amidxtape:      off
  • 設定
# vi /etc/xinetd.d/amanda
  • 変更
           disable                 = yes
          ↓
           disable                 = no
# vi /etc/xinetd.d/amandaidx
  • 変更
           disable                 = yes
          ↓
           disable                 = no
# vi /etc/xinetd.d/amidxtape
  • 変更
           disable                 = yes
          ↓
           disable                 = no
  • 初期設定
# /etc/init.d/xinetd restart
xinetd を停止中:                                           [  OK  ]
xinetd を起動中:                                           [  OK  ]
  • 確認
# chkconfig --list | grep am
        amanda:         on
        amandaidx:      on
        amidxtape:      on

(2)hosts登録

  • hosts登録
# vi /etc/hosts
  • 最終行に追加
    192.168.0.10           amandaServer
    192.168.0.20           hogehogeServer

(3)amandahosts登録

  • amandahosts登録
# vi /var/lib/amanda/.amandahosts
  • 最終行に追加
    amandaServer amanda   #バックアップ用
    amandaServer root     #リストア用
    hogehogeServer amanda #バックアップ用
    hogehogeServer root   #リストア用

amanda.conf設定

amanda.conf設定

  • amanda.conf設定
# vi /etc/amanda/DailySet1/amanda.conf
  • 修正
    dumpcycle 4 weeks       # the number of days in the normal dump cycle
    runspercycle 20         # the number of amdump runs in dumpcycle days
                            # (4 weeks * 5 amdump runs per week -- just weekdays)
    tapecycle 25 tapes      # the number of tapes in rotation
      ↓
    dumpcycle 1 weeks       # the number of days in the normal dump cycle
    runspercycle 7 days     # the number of amdump runs in dumpcycle days
                            # (4 weeks * 5 amdump runs per week -- just weekdays)
    tapecycle 8 tapes       # the number of tapes in rotation
    ★週1回フルバックアップ、毎日1回差分バックアップ、テープ8本
    →エラー時に前回フルバックアップが消えないようtapecycleは「runspercycle + 1」を設定
  • 追加
    ### 仮想テープの設定
    define tapetype HDD {
           length 1024 mbytes
    }
  • 変更
    tapetype HP-DAT         # what kind of tape it is (see tapetypes below)
      ↓
    tapetype HDD            # what kind of tape it is (see tapetypes below)
  • 変更
    tpchanger "chg-manual"  # the tape-changer glue script
    tapedev "null:"         # the no-rewind tape device to be used
      ↓
    tpchanger "chg-disk"    # the tape-changer glue script
    tapedev "file:/var/lib/amanda/vtl" # the no-rewind tape device to be used
  • 変更
    holdingdisk hd1 {
        comment "main holding disk"
        directory "/dumps/amanda"   # where the holding disk is
      ↓
    holdingdisk hd1 {
        comment "main holding disk"
        directory "/var/lib/amanda/holdingdisk"   # where the holding disk is
  • 変更
    define dumptype global {
        comment "Global definitions"
        # index yes
      ↓
    define dumptype global {
        comment "Global definitions"
        index yes   ←コメントアウト

holdingdisk作成

  • holdingdisk作成
# mkdir /var/lib/amanda/holdingdisk

tapelist作成

  • tapelist作成
# touch /etc/amanda/DailySet1/tapelist
  • 権限変更
# chmod 660 /etc/amanda/DailySet1/tapelist
  • オーナ変更
# chown amanda:disk /etc/amanda/DailySet1/tapelist
  • 確認
# ls -l /etc/amanda/DailySet1/
-rw-r--r-- 1 amanda disk 26635  3月  4 17:48 amanda.conf
-rw-r--r-- 1 amanda disk  2099  9月  4  2009 disklist
-rw-rw---- 1 amanda disk     0  3月  4 17:52 tapelist

disklistの設定

  • disklistの設定
# vi /etc/amanda/DailySet1/disklist
  • 最終行に追加
    amandaServer   /etc comp-root-tar
    hogehogeServer /etc comp-root-tar

仮想テープドライブ作成

  • amandaユーザでログイン
# su amanda
$

仮想テープドライブ作成

  • 仮想テープドライブ作成
$ mkdir /var/lib/amanda/vtl
$ mkdir /var/lib/amanda/vtl/slot1
$ mkdir /var/lib/amanda/vtl/slot2
$ mkdir /var/lib/amanda/vtl/slot3
$ mkdir /var/lib/amanda/vtl/slot4
$ mkdir /var/lib/amanda/vtl/slot5
$ mkdir /var/lib/amanda/vtl/slot6
$ mkdir /var/lib/amanda/vtl/slot7
$ mkdir /var/lib/amanda/vtl/slot8
  • 確認
$ ls -l /var/lib/amanda/vtl
drwxr-xr-x 2 amanda disk 4096  3月  8 15:28 slot1
drwxr-xr-x 2 amanda disk 4096  3月  8 15:28 slot2
drwxr-xr-x 2 amanda disk 4096  3月  8 15:28 slot3
drwxr-xr-x 2 amanda disk 4096  3月  8 15:29 slot4
drwxr-xr-x 2 amanda disk 4096  3月  8 15:29 slot5
drwxr-xr-x 2 amanda disk 4096  3月  8 15:30 slot6
drwxr-xr-x 2 amanda disk 4096  3月  8 15:30 slot7
drwxr-xr-x 2 amanda disk 4096  3月  8 15:32 slot8

仮想テープ情報管理ファイル作成

  • 仮想テープ情報管理ファイル作成
$ touch /var/lib/amanda/vtl/info

仮想テープドライブセット

  • 仮想テープドライブにslot1にセット
$ ln -s /var/lib/amanda/vtl/slot1 /var/lib/amanda/vtl/data
  • 確認
$ ls -l /var/lib/amanda/vtl
lrwxrwxrwx 1 amanda disk   25  3月  8 15:30 data -> /var/lib/amanda/vtl/slot1
-rw-r--r-- 1 amanda disk   11  3月  8 15:32 info
drwxr-xr-x 2 amanda disk 4096  3月  8 15:28 slot1
drwxr-xr-x 2 amanda disk 4096  3月  8 15:28 slot2
drwxr-xr-x 2 amanda disk 4096  3月  8 15:28 slot3
drwxr-xr-x 2 amanda disk 4096  3月  8 15:29 slot4
drwxr-xr-x 2 amanda disk 4096  3月  8 15:29 slot5
drwxr-xr-x 2 amanda disk 4096  3月  8 15:30 slot6
drwxr-xr-x 2 amanda disk 4096  3月  8 15:30 slot7
drwxr-xr-x 2 amanda disk 4096  3月  8 15:32 slot8
  • 仮想テープのラベル付け
$ /usr/sbin/amlabel DailySet1 DailySet1-01 slot 1
$ /usr/sbin/amlabel DailySet1 DailySet1-02 slot 2
$ /usr/sbin/amlabel DailySet1 DailySet1-03 slot 3
$ /usr/sbin/amlabel DailySet1 DailySet1-04 slot 4
$ /usr/sbin/amlabel DailySet1 DailySet1-05 slot 5
$ /usr/sbin/amlabel DailySet1 DailySet1-06 slot 6
$ /usr/sbin/amlabel DailySet1 DailySet1-07 slot 7
$ /usr/sbin/amlabel DailySet1 DailySet1-08 slot 8
  • 確認
$ ls -l /var/lib/amanda/
drwxr-xr-x  3 amanda disk 4096  3月  4 16:15 DailySet1
drwxr-xr-x  2 amanda disk 4096  3月  8 15:32 gnutar-lists
drwxr-xr-x  2 amanda disk 4096  3月  8 15:32 holdingdisk
drwxr-xr-x 10 amanda disk 4096  3月  8 15:30 vtl

動作確認

  • amcheck動作確認
$ /usr/sbin/amcheck DailySet1
Amanda Tape Server Host Check
-----------------------------
Holding disk /var/lib/amanda/holdingdisk: 4646724 KB disk space available, using 4544324 KB
slot 8: read label `DailySet1-08', date `20110308'
slot 1: read label `DailySet1-01', date `X'
NOTE: skipping tape-writable test
Tape DailySet1-01 label ok
Server check took 0.219 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 2 hosts checked in 0.037 seconds, 0 problems found
(brought to you by Amanda 2.5.0p2)
  • 手動バックアップテスト
$ /usr/sbin/amdump DailySet1
  • 確認
$ /usr/sbin/amadmin DailySet1 find
Scanning /var/lib/amanda/holdingdisk...
date       host           disk     lv tape or file file part status
2011-03-08 amandaServer   /etc      0 DailySet1-01    2   -- OK
2011-03-08 hogehogeServer /etc      0 DailySet1-01    1   -- OK

自動実行登録

  • 「amanda」ユーザログイン
# su amanda
$
  • クーロン確認
$ crontab -l
no crontab for amanda
  • クーロン作成
$ crontab -e
  • 追加
    0 16 * * *    /usr/sbin/amcheck -m DailySet1
    45 0 * * *    /usr/sbin/amdump DailySet1
  • 確認
$ crontab -l
0 16 * * *    /usr/sbin/amcheck -m DailySet1
45 0 * * *    /usr/sbin/amdump DailySet1

リストア

amrecoverによるリストア

クライアント側の操作でリストアを実施。ディレクトリ単位で細かくバックアップが可能

  • 解凍用ワークエリアを作成
# mkdir temp
# ls -l
drwxr-xr-x 2 hogehoge hogehoge 4096  2月 10 15:24 Desktop
drwxr-xr-x 2 root     root     4096  3月  8 16:34 temp
  • リカバリコマンド実施
# /usr/sbin/amrecover -s amandaServer -t amandaServer -C DailySet1
AMRECOVER Version 2.5.0p2. Contacting server on amandaServer ...
220 amandaServer AMANDA index server (2.5.0p2) ready.
200 Access OK
Setting restore date to today (2011-03-08)
200 Working date set to 2011-03-08.
Scanning /var/lib/amanda/holdingdisk...
200 Config set to DailySet1.
200 Dump host set to amandaServer.
Trying disk / ...
Trying disk rootfs ...
Can't determine disk and mount point from $CWD '/home/hogehoge'
  • 確認
amrecover> listdisk
200- List of disk for host hogehogeServer
201- /etc
200 List of disk for host hogehogeServer
  • リカバリ対象セット
amrecover> setdisk /etc
200 Disk set to /etc.
  • 作業エリアに移動
amrecover> lcd temp
  • 確認
amrecover> lpwd
/home/hogehoge/temp
  • リストア対象をバックアップファイルからロード
amrecover> add *
Added dir /yum at date 2011-03-08
Added dir /yum.repos.d at date 2011-03-08
Added /yum.conf

  :

Added /.pwd.lock
Added dir / at date 2011-03-08
  • リストア実施
amrecover> extract
Extracting files using tape drive null: on host amandaServer.
The following tapes are needed: DailySet1-01
Restoring files into directory /home/hogehoge/temp
Continue [?/Y/n]? y
Extracting files using tape drive null: on host amandaServer.
Load tape DailySet1-01 now
Continue [?/Y/n/s/t]? y
./
./NetworkManager/
./NetworkManager/VPN/

  :

tar: ./yum: アーカイブ内に見つかりません
tar: 処理中にエラーが起きましたが、最後まで処理してからエラー終了させました
amrecover: Extractor child exited with status 2
extract_list - child returned non-zero status: 1
Continue [?/Y/n/r]? y

★「処理中にエラーが起きましたが、最後まで処理してからエラー終了させました」は気にしなくてOK

  • 終了
amrecover> exit
200 Good bye.
  • 確認
# ls temp
DIR_COLORS            host.conf       rc
DIR_COLORS.xterm      hosts           rc.d
NetworkManager        hosts.allow     rc.local

  :

amrestoreによるリストア

サーバ側でリストアファイルをtarにて出力後、クライアント側でtarにて解凍、手動でリストアする。

  • 作業エリア作成
# mkdir temp
# ls -l
drwxr-xr-x 2 hogehoge hogehoge 4096  2月 11 18:54 Desktop
drwxr-xr-x 2 root     root     4096  3月  8 17:00 temp
  • amandaユーザログイン
# su amanda
  • バックアップファイル確認
$ /usr/sbin/amadmin DailySet1 find
Scanning /var/lib/amanda/holdingdisk...
date       host           disk     lv tape or file file part status
2011-03-08 amandaServer   /etc      0 DailySet1-01    2   -- OK
2011-03-08 hogehogeServer /etc      0 DailySet1-01    1   -- OK
  • リストアテープセット
$ /usr/sbin/amtape DailySet1 label DailySet1-01
amtape: scanning for tape with label DailySet1-01
changer: got exit: 0 str: 1 8 1
changer_query: changer return was 8 1
changer_query: searchable = 0
changer_find: looking for DailySet1-01 changer is searchable = 0
changer: got exit: 0 str: 1 file:/var/lib/amanda/vtl
amtape: slot 1: date 20110308 label DailySet1-01 (exact label match)
amtape: label DailySet1-01 is now loaded.
  • テープ巻き戻し
$ /usr/sbin/ammt -f file:/var/lib/amanda/vtl rewind
  • 戻り
$ exit
exit
  • 作業エリアへ移動
# cd temp
  • 確認
# pwd
/home/hogehoge/temp
  • リストアファイル出力
# amrestore file:/var/lib/amanda/vtl hogehogeServer /etc
amrestore:   1: restoring hogehogeServer._etc.20110308.0
amrestore:   2: skipping amandaServer._etc.20110308.0
amrestore:   3: reached end of tape: date 20110308
  • 確認
# ls -l
-rw-r----- 1 root root 99123200  3月  8 17:02 hogehogeServer._etc.20110308.0
-rw------- 1 root root     1015  2月 11 18:45 anaconda-ks.cfg
-rw-r--r-- 1 root root    35202  2月 11 18:44 install.log
-rw-r--r-- 1 root root     2913  2月 11 18:44 install.log.syslog
  • クライアントサーバにファイルを移動

★「hogehogeServer._etc.20110308.0」をクライアント側に移動(ftpやwgetを利用)

  • クライアント側でファイルを解凍
# tar xvf hogehogeServer._etc.20110308.0
./
./NetworkManager/
./NetworkManager/VPN/
./NetworkManager/dispatcher.d/

  :

./yum.repos.d/intra-repo.repo
./yum/pluginconf.d/fastestmirror.conf

★解凍ファイルを手動で/etcにコピー

遭遇したトラブル

/usr/sbin/amcheck でエラーが発生

問題:
以下コマンドでエラーとなる

# /usr/sbin/amcheck DailySet1
amcheck: running as user "root" instead of "amanda"

原因:
「amanda」ユーザで実行すべきところを「root」で実行していた
以下コマンドで「amanda」ユーザに変更

# su amanda

「/usr/sbin/amcheck」 でエラーが発生

問題:
以下コマンドでエラーとなる

$ /usr/sbin/amcheck DailySet1

ERROR: NAK localhost: access as amanda not allowed from

原因:
「/etc/host」の設定が誤っている。ホスト側、クライアント側双方とも確認が必要。
指定したホスト名でpingが通るか確認すること。

amcheckで「not an amanda tape」エラーが発生

問題:

「/usr/sbin/amcheck DailySet1」で以下エラーが発生。バックアップが取れない。

slot 1: not an amanda tape (Read 0 bytes)
slot 2: not an amanda tape (Read 0 bytes)
slot 3: not an amanda tape (Read 0 bytes)
slot 4: not an amanda tape (Read 0 bytes)
slot 5: not an amanda tape (Read 0 bytes)
slot 6: not an amanda tape (Read 0 bytes)
slot 7: not an amanda tape (Read 0 bytes)
slot 8: not an amanda tape (Read 0 bytes)

原因:
仮想テープドライブを「amanda」ユーザで作成していなかったため。
特に「仮想テープのラベル付け」は別ユーザで作成した場合、chmodでユーザ変更しても駄目。
必ず「amanda」ユーザで

/usr/sbin/amlabel -f DailySet1 DailySet1-0x slot x

として再作成すること。

crontabコマンド実行不可

問題:

crontabコマンドが以下エラーで実行できない

$ crontab -e
bash: crontab: command not found

原因:
「vixie-cron」がインストールされていない。yumでインストール実施

# yum install vixie-cron

自動収集が出来ない

問題:

crontabコマンドで登録した時間を過ぎても自動収集が動かずバックアップが作成されない

原因:
crontabインストール後 crondが起動されていない。以下コマンドで実行を確認

# /etc/rc.d/init.d/crond status
crond (pid  5420) を実行中...

謝辞

テキスト作成にあたり、以下サイトを参考にさせて頂きました。ありがとうございます。

http://www.oss-d.net/amanda/2.5
http://www5.atwiki.jp/choc-net/pages/16.html
http://www.express.nec.co.jp/linux/distributions/knowledge/system/crond.html