CentOS 6.3でamandaを使ってみる

 article  Comments Off on CentOS 6.3でamandaを使ってみる
Aug 052012
 

CentOS 6.3でamanda使ってバックアップを試してみました。
テープは持っていないのでハードディスクへの取得です。

バックアップ取得処理をおこなうサーバーはcentos2、取得対象はcentos1とcentos2のホスト名になります。

# yum install -y amanda-server amanda-client amanda xinetd

xinetdとamandaサービスを有効化します。

# chkconfig amanda on
# chkconfig xinetd on
# service xinetd start

インストールするとDailySet1というバックアップ設定が作られるので、こちらを修正していきます。

$ vi /etc/amanda/DailySet1/amanda.conf

内容はこんな感じ。テープではなくディスクにバックアップを取得するので、/var/lib/amanda/template.d/amanda-harddisk.confを模倣しています。世代数などは適当です。

org    "DailySet1"             # your organization name for reports
mailto "amandabackup"          # space separated list of operators at your site
dumpcycle 1 week               # the number of days in the normal dump cycle
runspercycle 7                 # the number of amdump runs in dumpcycle days
                               # (1 week * 5 amdump runs per week -- just weekdays)
tapecycle 14 tapes             # the number of tapes in rotation
                               # 1 week (dumpcycle) times 5 tapes per week (just
                               # the weekdays) plus a few to handle errors that
                               # need amflush and so we do not overwrite the full
                               # backups performed at the beginning of the previous
                               # cycle
runtapes 1                     # number of tapes to be used in a single run of amdump
tpchanger "chg-disk"           # the tape-changer glue script
tapedev "file:/var/lib/amanda/vtapes/DailySet1" # the no-rewind tape device to be used
changerfile "/etc/amanda/DailySet1/changer.conf"
changerdev  "/dev/null"
tapetype HARDDISK              # what kind of tape it is
labelstr "^DailySet1-[0-9][0-9]*$" # label constraint regex: all tapes must match
dtimeout 1800                  # number of idle seconds before a dump is aborted.
ctimeout 30                    # maximum number of seconds that amcheck waits
                               # for each client host
etimeout 300                   # number of seconds per filesystem for estimates.

infofile "/var/lib/amanda/DailySet1/curinfo"
logdir   "/var/lib/amanda/DailySet1/"
indexdir "/var/lib/amanda/DailySet1/index"

define dumptype global {
        comment "Global definitions"
#        auth "bsdtcp"
}

#define application-tool and dumptype for the amgtar application
define application-tool app_amgtar {
        comment "amgtar"
        plugin  "amgtar"
        #property "GNUTAR-PATH" "/path/to/gtar"
        #property "GNUTAR-LISTDIR" "/path/to/gnutar_list_dir"
}

define dumptype gui-base {
        global
        program "APPLICATION"
        application "app_amgtar"
        comment "gui base dumptype dumped with tar"
        compress none
        index yes
}

define tapetype HARDDISK {
        length 100000 mbytes
}

includefile "/var/lib/amanda/template.d/dumptypes"

amandabackupユーザーでamcheckを実行してみます。

$ amcheck DailySet1
Amanda Tape Server Host Check
-----------------------------
NOTE: tapelist will be created on the next run.
slot 1:Found an empty or non-amanda tape.
slot 2:Found an empty or non-amanda tape.
slot 3:Found an empty or non-amanda tape.
slot 4:Found an empty or non-amanda tape.
slot 5:Found an empty or non-amanda tape.
slot 6:Found an empty or non-amanda tape.
slot 7:Found an empty or non-amanda tape.
slot 8:Found an empty or non-amanda tape.
slot 9:Found an empty or non-amanda tape.
slot 10:Found an empty or non-amanda tape.
slot 11:Found an empty or non-amanda tape.
slot 12:Found an empty or non-amanda tape.
slot 13:Found an empty or non-amanda tape.
slot 14:Found an empty or non-amanda tape.
       (expecting a new tape)
NOTE: conf info dir /var/lib/amanda/DailySet1/curinfo does not exist
NOTE: it will be created on the next run.
NOTE: index dir /var/lib/amanda/DailySet1/index/centos1 does not exist
NOTE: it will be created on the next run.
NOTE: index dir /var/lib/amanda/DailySet1/index/centos2 does not exist
NOTE: it will be created on the next run.
Server check took 5.723 seconds

Amanda Backup Client Hosts Check
--------------------------------
Client check: 2 hosts checked in 2.056 seconds.  0 problems found.

(brought to you by Amanda 2.6.1p2)
$

仮想テープ用ディレクトリとラベルを作成します。先のamanda.confに”tapecycle 14 tapes”としていますのでslot1~14まで作成します。

$ mkdir -p /var/lib/amanda/vtapes/DailySet1
$ for i in `seq 1 14`; do mkdir /var/lib/amanda/vtapes/DailySet1/slot$i; done
$ for i in `seq 1 14`; do amlabel DailySet1 DailySet1-`printf %02d $i` slot $i; done
labeling tape in slot 1 (file:/var/lib/amanda/vtapes/DailySet1):
Reading label...
Found an empty tape.
Writing label DailySet1-01..
Checking label...
Success!
labeling tape in slot 2 (file:/var/lib/amanda/vtapes/DailySet1):
Reading label...
Found an empty tape.
Writing label DailySet1-02..
Checking label...
Success!
~中略~
labeling tape in slot 14 (file:/var/lib/amanda/vtapes/DailySet1):
Reading label...
Found an empty tape.
Writing label DailySet1-14..
Checking label...
Success!
$

バックアップ対象は/etc/amanda/DailySet1/disklistに記述します。さしあたって各サーバーの/etc配下を取得。

centos1 /etc comp-root-tar
centos2 /etc comp-root-tar

ここまで設定したらamdumpで実際にバックアップを取得してみます(amandabackupユーザーで実行)。

$ amdump DailySet1

エラーがなければ何も出力されずに終了しますので、amadminコマンドでバックアップリストを表示してみます。

$ amadmin DailySet1 find

date                host    disk lv tape or file file part status
2012-08-04 23:50:02 centos1 /etc  1 DailySet1-10    1  1/1 OK
2012-08-04 23:50:02 centos2 /etc  0 DailySet1-10    1  1/1 OK
You have new mail in /var/spool/mail/amandabackup
$

無事取得できたようです。

リストアには/etc/amanda/amanda-client.confの作成とxinetd設定の変更が必要です。

$ cat /etc/amanda/amanda-client.conf
#
# amanda.conf - sample Amanda client configuration file.
#
# This file normally goes in /etc/amanda/amanda-client.conf.
#

conf "DailySet1"        # your config name

index_server "centos2"  # your amindexd server
tape_server  "centos2"  # your amidxtaped server
tapedev      "file:/var/lib/amanda/vtapes/DailySet1"    # your tape device
                        # if not set, Use configure or ask server.
                        # if set to empty string "", ask server
                        # amrecover will use the changer if set to the value
                        # of 'amrecover_changer' in the server amanda.conf.

#   auth        - authentication scheme to use between server and client.
#                 Valid values are "bsd", "bsdudp", "bsdtcp", "krb5", "local",
#                 "rsh" and "ssh".
#                 Default: [auth "bsdtcp"]
auth "bsd"

#ssh_keys ""                    # your ssh keys file if you use ssh auth

#resolves "resource temporarily unavailable" bug
unreserved-tcp-port 1025,65535
$

取得サーバーであるcentos2側では/etc/xinetd.d/amandaのserver_argsに修正が必要です(amindexd amidxtapedを追加)。

        server_args             = -auth=bsd amdump

        server_args             = -auth=bsd amdump amindexd amidxtaped

rootユーザーでamrecoverを実行してみます。

# amrecover
AMRECOVER Version 2.6.1p2. Contacting server on centos2 ...
220 centos2 AMANDA index server (2.6.1p2) ready.
Setting restore date to today (2012-08-04)
200 Working date set to 2012-08-04.
200 Config set to DailySet1.
200 Dump host set to centos2.
Use the setdisk command to choose dump disk to recover
amrecover> listdisk
200- List of disk for host centos2
201- /etc
200 List of disk for host centos2
amrecover> setdisk /etc
200 Disk set to /etc.
amrecover> 

あとはlsで取得されているファイルの一覧を確認して、リストア対象をadd、extractすればカレントディレクトリに展開されます(カレントディレクトリはlcdで変更可)。