■debian WheezyにAmandaテープバックアップを導入(バックアップ&リストア)
2年ほど前にもSqueezeでやった。
今回はもう少しちゃんとしたい。
バックアップツールのamandaを使ってみた
http://d.hatena.ne.jp/labunix/20110819
amanda 仮想テープバックアップ【backup宛のメール】
http://d.hatena.ne.jp/labunix/20110820
manda仮想テープでバックアップ/リストア
http://d.hatena.ne.jp/labunix/20110821
■パッケージの導入
inet/xinetのどちらも利用可能。今回はxinetdを選択。
$ apt-cache search ^amanda*
amanda-client - 先進的な Maryland 自動ネットワークディスクアーカイバ (クライアント)
amanda-common - Advanced Maryland Automatic Network Disk Archiver (ライブラリ)
amanda-server - Advanced Maryland Automatic Network Disk Archiver (サーバ)
$ sudo apt-get install -y ^amanda-*
$ echo "xinetd gawk gnuplot readline-common" | sudo apt-get install -y `xargs`
■設定確認。
bsdudpが無くなっている。
今回はデフォルトのtcpのままとする。
$ grep -v "^\#\|^\$" /etc/inetd.conf
amanda stream tcp nowait backup /usr/lib/amanda/amandad amandad -auth=bsdtcp amdump amindexd amidxtaped
$ man amanda.conf 2>/dev/null | grep "auth \"[bsd\|tcp]"
auth "bsd"
auth "bsdtcp"
$ grep "disable\|default" /etc/xinetd.d/amanda
disable = no
$ ps aux | grep xinetd | cut -c 76-
xinetd -pidfile /var/run/xinetd.pid -stayalive -inetd_compat -inetd_ipv6
d
■xinetdのユーザの変更
amandabackupというユーザは存在しない。backupユーザとするべきことが分かる。
$ sudo grep xinetd /var/log/syslog | grep -i "unknown\|error"
Sep 18 22:26:26 amanda xinetd[5436]: Unknown user: amandabackup [file=/etc/xinetd.d/amanda] [line=13]
Sep 18 22:26:26 amanda xinetd[5436]: Error parsing attribute user - DISABLING SERVICE [file=/etc/xinetd.d/amanda] [line=13]
$ grep backup /etc/passwd
backup:x:34:34:backup:/var/backups:/bin/sh
$ grep backup /etc/xinetd.d/amanda
user = amandabackup
■設定変更
$ sudo sed -i s/"amanda\(backup\)"/"\1"/ /etc/xinetd.d/amanda
s$ grep "user\|group" /etc/xinetd.d/amanda
user = backup
group = disk
groups = yes
$ sudo /etc/init.d/xinetd restart
[ ok ] Stopping internet superserver: xinetd.
[ ok ] Starting internet superserver: xinetd.
■ドキュメントにあるように4つのステップで設定する。
$ lv -s /usr/share/doc/amanda-server/README.Debian.gz | grep -A 1 "^[0-9]\. " | grep -v "^\-"
1. Create a directory under /etc/amanda for your backup config, we’ll assume
a name 'DailySet1' as our example.
2. populate this directory with config files. At a minimum, you need
amanda.conf and disklist.
3. Make sure that /etc/amanda and all the files under it are owner and group
backup with directory permissions of 770 and file permissions of 660.
3. Prepare the "holding disk" if you plan to use one (highly recommended!) by
ensuring user backup can access it. See the note below indicating that it
4. Install a suitable crontab for user backup. If you used DailySet1 as your
configuration name, you can just install the provided example. If you
■以下がその4つのStepに対応するコマンド。
$ sudo test -d /etc/amanda/DailySet1 || sudo mkdir -p /etc/amanda/DailySet1
$ sudo cp /usr/share/doc/amanda-server/examples/{amanda.conf.gz,disklist,} /etc/amanda/DailySet1 && \
sudo gunzip /etc/amanda/DailySet1/amanda.conf.gz
$ sudo chown -R backup:disk /etc/amanda
$ sudo crontab -u backup /usr/share/doc/amanda-server/examples/crontab.amanda && \
sudo -u backup crontab -l | grep -v ^#
0 16 * * 1-5 /usr/sbin/amcheck -m DailySet1
45 0 * * 2-6 /usr/sbin/amdump DailySet1
$ sudo /etc/init.d/xinetd restart && \
sudo grep "$(env LANG=C date '+%H\:%M\:%S')" /var/log/syslog | grep xinetd
[ ok ] Stopping internet superserver: xinetd.
[ ok ] Starting internet superserver: xinetd.
Sep 18 23:06:45 amanda xinetd[9746]: Exiting...
Sep 18 23:06:45 amanda xinetd[9811]: Reading included configuration file: /etc/xinetd.d/amanda [file=/etc/xinetd.conf] [line=14]
Sep 18 23:06:45 amanda xinetd[9811]: Reading included configuration file: /etc/xinetd.d/chargen [file=/etc/xinetd.d/chargen] [line=18]
Sep 18 23:06:45 amanda xinetd[9811]: Reading included configuration file: /etc/xinetd.d/daytime [file=/etc/xinetd.d/daytime] [line=28]
Sep 18 23:06:45 amanda xinetd[9811]: Reading included configuration file: /etc/xinetd.d/discard [file=/etc/xinetd.d/discard] [line=26]
Sep 18 23:06:45 amanda xinetd[9811]: Reading included configuration file: /etc/xinetd.d/echo [file=/etc/xinetd.d/echo] [line=25]
Sep 18 23:06:45 amanda xinetd[9811]: Reading included configuration file: /etc/xinetd.d/time [file=/etc/xinetd.d/time] [line=26]
Sep 18 23:06:45 amanda xinetd[9811]: removing duplicate service amanda [file=/etc/inetd.conf] [line=38]
Sep 18 23:06:45 amanda xinetd[9811]: removing chargen
Sep 18 23:06:45 amanda xinetd[9811]: removing chargen
Sep 18 23:06:45 amanda xinetd[9811]: removing daytime
Sep 18 23:06:45 amanda xinetd[9811]: removing daytime
Sep 18 23:06:45 amanda xinetd[9811]: removing discard
Sep 18 23:06:45 amanda xinetd[9811]: removing discard
Sep 18 23:06:45 amanda xinetd[9811]: removing echo
Sep 18 23:06:45 amanda xinetd[9811]: removing echo
Sep 18 23:06:45 amanda xinetd[9811]: removing time
Sep 18 23:06:45 amanda xinetd[9811]: removing time
Sep 18 23:06:45 amanda xinetd[9811]: xinetd Version 2.3.14 started with libwrap loadavg options compiled in.
Sep 18 23:06:45 amanda xinetd[9811]: Started working: 1 available service
■初期状態では設定がメチャメチャなので一旦コメントアウトします。
$ sudo amcheck DailySet1
"/etc/amanda/DailySet1/disklist", line 50: undefined network interface 'LE0'
$ sudo sed -i s/"^[A-z0-9\t {}]"/"#&"/g /etc/amanda/DailySet1/disklist
■初回チェック
$ sudo -u backup amcheck DailySet1
Amanda Tape Server Host Check
-----------------------------
NOTE: tapelist will be created on the next run.
ERROR: holding dir /dumps/amanda (No such file or directory), you must create a directory.
slot 0: Can't open tape device /dev/YOUR-TAPE-DEVICE-HERE: No such file or directory
Can't open tape device /dev/YOUR-TAPE-DEVICE-HERE: No such file or directory
Insert a new volume in tape:/dev/YOUR-TAPE-DEVICE-HERE
and press <enter> enter, or ^D to abort.
ERROR: Aborted by user
NOTE: conf info dir /etc/amanda/DailySet1/curinfo does not exist
NOTE: it will be created on the next run.
Server check took 4.059 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 0 hosts checked in 0.000 seconds. 0 problems found.
(brought to you by Amanda 3.3.1)
■修正する箇所の洗い出し。
$ sudo grep "DailySet1\|dumps\|YOUR" /etc/amanda/DailySet1/amanda.conf | grep -v "^#"
org "DailySet1"
dumpuser "backup"
tapedev "tape:/dev/YOUR-TAPE-DEVICE-HERE"
maxdumpsize -1
labelstr "^DailySet1-[0-9][0-9]*$"
directory "/dumps/amanda"
infofile "/etc/amanda/DailySet1/curinfo"
logdir "/etc/amanda/DailySet1"
indexdir "/etc/amanda/DailySet1/index"
■ディレクトリの作成
$ sudo mkdir -p /etc/amanda/DailySet1/{curinfo,index};sudo mkdir -p /dumps/amanda;sudo chown -R backup:disk /etc/amanda /dumps
$ sudo -u backup amcheck DailySet1
Amanda Tape Server Host Check
-----------------------------
NOTE: tapelist will be created on the next run.
Holding disk /dumps/amanda: 17666048 KB disk space available, using 17563648 KB
slot 0: Can't open tape device /dev/YOUR-TAPE-DEVICE-HERE: No such file or directory
Can't open tape device /dev/YOUR-TAPE-DEVICE-HERE: No such file or directory
Insert a new volume in tape:/dev/YOUR-TAPE-DEVICE-HERE
and press <enter> enter, or ^D to abort.
ERROR: Aborted by user
Server check took 18.389 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 0 hosts checked in 0.000 seconds. 0 problems found.
(brought to you by Amanda 3.3.1)
■仮想テープの設定
$ sudo grep "^## tapedev" /etc/amanda/DailySet1/amanda.conf
$ sudo -u backup touch /etc/amanda/DailySet1/tapelist; \
sudo mkdir -p /var/amanda/vtapes/DailySet1/slots && \
sudo chown -R backup:disk /var/amanda
$ sudo -u backup sed -i s%"\(tapedev .\)tape:/dev/YOUR-TAPE-DEVICE-HERE"%"\1file:/var/amanda/vtapes/DailySet1/slots"% \
/etc/amanda/DailySet1/amanda.conf
■「slot 0」が無いとのエラー。
$ sudo -u backup amcheck DailySet1Amanda Tape Server Host Check
-----------------------------
Holding disk /dumps/amanda: 17666048 KB disk space available, using 17563648 KB
slot 0: Error checking directory /var/amanda/vtapes/DailySet1/slots/data/: No such file or directory
Error checking directory /var/amanda/vtapes/DailySet1/slots/data/: No such file or directory
Insert a new volume in file:/var/amanda/vtapes/DailySet1/slots
and press <enter> enter, or ^D to abort.
ERROR: Aborted by user
Server check took 27.570 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 0 hosts checked in 0.000 seconds. 0 problems found.
(brought to you by Amanda 3.3.1)
■「slot 0」の作成
ローテーションの数だけ作成する。
$ sudo grep tapecycle /etc/amanda/DailySet1/amanda.conf --color
tapecycle 25 tapes
$ cd /var/amanda/vtapes/DailySet1/slots && \
for n in `seq 1 25`;do udo -u backup kdir slot$n;done && \
sudo -u backup ln -s slot01 data
■slotが空。
$ sudo -u backup amcheck DailySet1
Amanda Tape Server Host Check
-----------------------------
Holding disk /dumps/amanda: 17666048 KB disk space available, using 17563648 KB
slot 0: contains an empty volume
File 0 not found
Insert a new volume in file:/var/amanda/vtapes/DailySet1/slots
and press <enter> enter, or ^D to abort.
ERROR: Aborted by user
Server check took 15.750 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 0 hosts checked in 0.000 seconds. 0 problems found.
(brought to you by Amanda 3.3.1)
■slotに仮想テープをセットするテープチェンジャーの設定を追加する。
$ sudo grep tpchanger /etc/amanda/DailySet1/amanda.conf
$ sudo sed -i s%"^#.*tpchanger.*"%"&\n"'tpchanger "chg-disk"'% /etc/amanda/DailySet1/amanda.conf
$ sudo -u backup amtape DailySet1 show
amtape: scanning all 25 slots in changer:
slot 24: unlabeled volume
slot 25: unlabeled volume
slot 1: unlabeled volume
slot 2: unlabeled volume
slot 3: unlabeled volume
slot 4: unlabeled volume
slot 5: unlabeled volume
slot 6: unlabeled volume
slot 7: unlabeled volume
slot 8: unlabeled volume
slot 9: unlabeled volume
slot 10: unlabeled volume
slot 11: unlabeled volume
slot 12: unlabeled volume
slot 13: unlabeled volume
slot 14: unlabeled volume
slot 15: unlabeled volume
slot 16: unlabeled volume
slot 17: unlabeled volume
slot 18: unlabeled volume
slot 19: unlabeled volume
slot 20: unlabeled volume
slot 21: unlabeled volume
slot 22: unlabeled volume
slot 23: unlabeled volume
■ラベル付け、仮想テープをリセットしてロードする。
$ cd /var/amanda/vtapes/DailySet1/slots && \
for n in `seq 1 25`; do sudo -u backup amlabel DailySet1 DailySet1-$n slot $n; done
$ sudo -u backup amtape DailySet1 reset
changer is reset
$ sudo -u backup amtape DailySet1 current
slot 1: time X label DailySet1-1
changed to slot 1
■25本の仮想テープがチェンジャーに認識されている
$ sudo -u backup amtape DailySet1 show
amtape: scanning all 25 slots in changer:
slot 1: date X label DailySet1-1
slot 2: date X label DailySet1-2
slot 3: date X label DailySet1-3
slot 4: date X label DailySet1-4
slot 5: date X label DailySet1-5
slot 6: date X label DailySet1-6
slot 7: date X label DailySet1-7
slot 8: date X label DailySet1-8
slot 9: date X label DailySet1-9
slot 10: date X label DailySet1-10
slot 11: date X label DailySet1-11
slot 12: date X label DailySet1-12
slot 13: date X label DailySet1-13
slot 14: date X label DailySet1-14
slot 15: date X label DailySet1-15
slot 16: date X label DailySet1-16
slot 17: date X label DailySet1-17
slot 18: date X label DailySet1-18
slot 19: date X label DailySet1-19
slot 20: date X label DailySet1-20
slot 21: date X label DailySet1-21
slot 22: date X label DailySet1-22
slot 23: date X label DailySet1-23
slot 24: date X label DailySet1-24
slot 25: date X label DailySet1-25
■書き込みテストも成功。
$ sudo -u backup amcheck DailySet1
Amanda Tape Server Host Check
-----------------------------
Holding disk /dumps/amanda: 17666048 KB disk space available, using 17563648 KB
found in slot 25: volume 'DailySet1-25'
slot 25: volume 'DailySet1-25'
Will write to volume 'DailySet1-25' in slot 25.
NOTE: skipping tape-writable test
Server check took 0.776 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 0 hosts checked in 0.000 seconds. 0 problems found.
(brought to you by Amanda 3.3.1)
■バックアップのターゲットは容量の少ないスプールメールとし、
disklistでクライアントの設定を行う。
$ ls -l /var/spool/mail | cut -c 40-;ls -l /var/spool/mail/../mail | awk '(NF>4){print $5,$NF}'
/var/spool/mail -> ../mail
1984 backup
2322 labunix
$ hostname -f
amanda.tape.local
$ echo "`hostname -f`"' /var/mail comp-user-tar' | sudo tee -a /etc/amanda/DailySet1/disklist >/dev/null
■必要なディレクトリを作成、正常に認識された。
$ sudo -u backup mkdir -p /etc/amanda/DailySet1/{curinfo,index}/amanda.tape.local/_var_mail
$ sudo -u backup touch /etc/amanda/DailySet1/curinfo/amanda.tape.local/_var_mail/info
$ sudo chmod -R 750 /dumps/ /etc/amanda /var/amanda/ && \
sudo chown -R backup:disk /dumps/ /etc/amanda /var/amanda/
$ sudo sudo -u backup amcheck DailySet1
Amanda Tape Server Host Check
-----------------------------
Holding disk /dumps/amanda: 17661952 KB disk space available, using 17559552 KB
found in slot 25: volume 'DailySet1-25'
slot 25: volume 'DailySet1-25'
Will write to volume 'DailySet1-25' in slot 25.
NOTE: skipping tape-writable test
Server check took 0.709 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 1 host checked in 2.037 seconds. 0 problems found.
(brought to you by Amanda 3.3.1)
■現状は25本目が認識されているのでリセット
$ sudo -u backup amtape DailySet1 taper
found in slot 25: volume 'DailySet1-25'
slot 25: volume 'DailySet1-25'
Will write to volume 'DailySet1-25' in slot 25.
$ sudo -u backup amtape DailySet1 reset
sudo -u backup amtape DailySet1 taper
found in slot 1: volume 'DailySet1-1'
slot 1: volume 'DailySet1-1'
Will write to volume 'DailySet1-1' in slot 1.
■新しいテープとして認識されている。
$ sudo -u backup amstatus DailySet1
Using /etc/amanda/DailySet1/amdump.1
From 木 9月 19 00:45:01 JST 2013
SUMMARY part real estimated
size size
partition : 0
estimated : 0 0k
flush : 0 0k
failed : 0 0k ( 0.00%)
wait for dumping: 0 0k ( 0.00%)
dumping to tape : 0 0k ( 0.00%)
dumping : 0 0k 0k ( 0.00%) ( 0.00%)
dumped : 0 0k 0k ( 0.00%) ( 0.00%)
wait for writing: 0 0k 0k ( 0.00%) ( 0.00%)
wait to flush : 0 0k 0k (100.00%) ( 0.00%)
writing to tape : 0 0k 0k ( 0.00%) ( 0.00%)
failed to tape : 0 0k 0k ( 0.00%) ( 0.00%)
taped : 0 0k 0k ( 0.00%) ( 0.00%)
all dumpers active
taper status: Searching for a new tape
■手動バックアップ
$ sudo -u backup amdump DailySet1
$ sudo -u backup amstatus DailySet1
Using /etc/amanda/DailySet1/amdump.1
From 木 9月 19 01:31:21 JST 2013
amanda.tape.local:/var/mail 0 2k finished (1:31:27)
SUMMARY part real estimated
size size
partition : 1
estimated : 1 32k
flush : 0 0k
failed : 0 0k ( 0.00%)
wait for dumping: 0 0k ( 0.00%)
dumping to tape : 0 0k ( 0.00%)
dumping : 0 0k 0k ( 0.00%) ( 0.00%)
dumped : 1 2k 32k ( 6.25%) ( 6.25%)
wait for writing: 0 0k 0k ( 0.00%) ( 0.00%)
wait to flush : 0 0k 0k (100.00%) ( 0.00%)
writing to tape : 0 0k 0k ( 0.00%) ( 0.00%)
failed to tape : 0 0k 0k ( 0.00%) ( 0.00%)
taped : 1 2k 32k ( 6.25%) ( 6.25%)
tape 1 : 1 2k 32k ( 0.00%) DailySet1-1 (2 chunks)
4 dumpers idle : no-dumpers
taper status: Idle
taper qlen: 0
network free kps: 8000
holding space : 17559552k (100.00%)
chunker0 busy : 0:00:05 ( 81.64%)
dumper0 busy : 0:00:05 ( 81.45%)
taper busy : 0:00:00 ( 0.31%)
0 dumpers busy : 0:00:01 ( 18.48%) not-idle: 0:00:01 ( 98.08%)
1 dumper busy : 0:00:05 ( 81.50%) no-dumpers: 0:00:05 (100.00%)
■設定どおりにバックアップされた。
$ sudo -u backup amadmin DailySet1 find
date host disk lv tape or file file part status
2013-09-19 01:31:21 amanda.tape.local /var/mail 0 DailySet1-1 1 1/1 OK
■リストアテストの準備
$ sudo -u backup mkdir -p /tmp/amanda/restore
$ sudo -u backup cp /usr/share/doc/amanda-client/examples/amanda-client.conf /etc/amanda/ && \
sudo -u backup sed -i s/"localhost"/"`hostname -f`"/g /etc/amanda/amanda-client.conf
$ sudo -u backup grep YOUR /etc/amanda/amanda-client.conf
tapedev "tape:/dev/YOUR-TAPE-DEVICE-HERE"
$ sudo -u backup sed -i s%"\(tapedev .\)tape:/dev/YOUR-TAPE-DEVICE-HERE"%"\1file:/var/amanda/vtapes/DailySet1/slots"% \
/etc/amanda/amanda-client.conf
■リストア
$ sudo amrecover
AMRECOVER Version 3.3.1. Contacting server on amanda.tape.local ...
NAK: user root from amanda.tape.local is not allowed to execute the service amindexd:
Please add the line "amanda.tape.local root amindexd amidxtaped" to /var/backups/.amandahosts on the server
$ echo "amanda.tape.local root amindexd amidxtaped" | sudo -u backup tee -a /var/backups/.amandahosts
$ sudo amrecover
AMRECOVER Version 3.3.1. Contacting server on amanda.tape.local ...
220 amanda AMANDA index server (3.3.1) ready.
Setting restore date to today (2013-09-19)
200 Working date set to 2013-09-19.
200 Config set to DailySet1.
501 Host amanda is not in your disklist.
Trying host amanda.tape.local ...
200 Dump host set to amanda.tape.local.
Use the setdisk command to choose dump disk to recover
amrecover> listdisk
200- List of disk for host amanda.tape.local
201- /var/mail
200 List of disk for host amanda.tape.local
amrecover> setdisk /var/mail
200 Disk set to /var/mail.
amrecover> ls
2013-09-19-01-31-21 labunix
2013-09-19-01-31-21 backup
2013-09-19-01-31-21 .
amrecover> lcd /tmp/amanda/restore
amrecover> pwd
/var/mail
amrecover> lpwd
/tmp/amanda/restore
amrecover> setdevice DailySet1-1
Using tape "DailySet1-1".
Tape server unspecified, assumed to be amanda.tape.local.
amrecover> add *
Added file /labunix
Added file /backup
amrecover> extract
Extracting files using tape drive DailySet1-1 on host amanda.tape.local.
The following tapes are needed: DailySet1-1
Extracting files using tape drive DailySet1-1 on host amanda.tape.local.
Load tape DailySet1-1 now
Continue [?/Y/n/s/d]? Y
Restoring files into directory /tmp/amanda/restore
All existing files in /tmp/amanda/restore can be deleted
Continue [?/Y/n]? Y
./backup
./labunix
amrecover> quit
200 Good bye.
■リストア後の確認
ls -l /tmp/amanda/restore/ /var/mail/
/tmp/amanda/restore/:
合計 8
-rw-rw---- 1 backup mail 1984 9月 19 00:45 backup
-rw-rw---- 1 labunix mail 2322 9月 18 22:22 labunix
/var/mail/:
合計 8
-rw-rw---- 1 backup mail 4326 9月 19 01:31 backup
-rw-rw---- 1 labunix mail 0 9月 19 01:32 labunix