什么是Amanda?
- Amanda (Advanced Maryland Automatic Network Disk Archiver,马里兰高级自动网络磁盘存档工具) 是由马里兰大学的James da Silva在1991年所开发的。它是一个复杂的网络备份系统,能够把LAN中的所有计算机备份到一台服务器的磁带驱动器、磁盘或光盘上。
- Amanda本身并不是备份程序,它其实只是管理其他备份软件的封装软件。它使用系统上的dump和restore命令作为底层的备份软件,同时也能够使用tar命令,针对于windows计算机,Amanda还能够使用smbtar命令来实现备份。
- Amanda 支持类型广泛的磁带驱动器,并且能够使用磁带驱动器中的硬件压缩功能,或者也可以在数据通过网络之前使用客户机的compress以及gzip命令来压缩备份。其次,Amanda能够使用临时保存磁盘作为备份存档的中间存储媒介,以优化磁带的写入性能并保证在磁带出错时也能备份数据。
- Amanda是当前最流行的免费备份解决方案,目前Amanda最新的稳定版本是2.5.2p2。通过 http://www.amanda.org站点可以免费获得。
Amanda工作方式
- Amanda 综合使用完全备份和增量备份来保存所负责的全部数据,使用最小的、有可能是每日的备份集。一台 Amanda 服务器可以备份任意数量执行 Amanda 的客户机或是将连上 Amanda 服务器的计算机上的数据备份到一台磁带机上。一个常见的问题是,数据写入磁带机的时间将超过取行数据的时间,而 Amanda 解决了这个问题。它使用一个 “holding disk” 来同时备份几个文件系统。 Amanda 建立 “archive sets” 的一组磁带,用来备份在 Amanda 的配置文件中所列出的完整的文件系统。
- Amanda 的整体策略是:在每次周期中完成一次数据的完全备份,并且确保在两次完全转储之间备份所有更改的数据。传统的做法是先执行完全备份,然后在此期间执行增量备份。而Amanda 的工作方式不同的是,每次运行Amanda 都对部分数据进行完全备份,确切地说,就是在一个完整的备份周期内备份全部数据所需备份的其中一部分。例如,如果周期为 7 天,且一个周期内进行7次备份,则每天必须备份 1/7 的数据,以便在 7 天之内完成一次完全备份。除了这个“部分”完全备份外,Amanda 还对自最近一次完全备份后更改的数据进行增量备份。Amanda这种特有的备份策略,可以减少每次备份的数据量。
需求
系统文件的备份及还原(采用磁盘来作备份,即disk-to-disk方式)
- 将client端 /data文件夹中的数据进行备份,保证每天夜里1点备份。
- 客户端在必要时可进行还原
配置示例
部分参数如下:
hostname |
IP |
OS |
files path |
remark |
server |
192.168.4.142 |
CentOS 5.4 |
/amanda/DailySet1 |
amanda服务端(备份机) |
client |
192.168.4.138 |
CentOS 5.4 |
/data |
amanda客户端(多数据) |
HOSTS文件的配置:
-
#vim /etc/hosts #显示如下:
#Do not remove the following line, or various programs
#that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.4.138 client
192.168.4.142 server
-
#scp /etc/hosts 192.168.4.142:/etc/hosts #输入密码,传送
客户端的配置:
安装如下软件包:
- amanda
- amanda-client
- amanda-devel
-
#yum install -y amanda amdan-devel amanda-client(在使用yum的过程中保证可以联网或创建了本地yum源,这里暂不解释)
-
#vim /etc/xinetd.d/amanda #保证display项为no 显示如下:
# default: off
# description: The client for the Amanda backup system.
# This must be on for systems being backed up
# by Amanda.
service amanda
{ socket_type = dgram
protocol = udp
wait = yes
user = amanda
group = disk
server = /usr/lib/amanda/amandad
disable = no
}
-
#service xinetd restart
-
编辑.amandahosts文件,指定备份机的主机名和允许进行操作的用户
-
#vim /var/lib/amanda/.amandahosts #内容如下:
server amanda
#mkdir /data
#cp -R /etc/yum.repos.d /data
# ll /data
total 16
-rw-r--r-- 1 root root 2245 Oct 9 03:58 CentOS-Base.repo
-rw-r--r-- 1 root root 626 Oct 9 03:58 CentOS-Media.repo
服务端的配置:
安装如下软件包:
- amanda
- amanda-server
- amanda-devel
安装步骤如下:
-
yum install -y amanda amdan-devel amanda-server(在使用yum的过程中保证可以联网或创建了本地yum源,这里暂不解释)
-
-
- #vim /etc/xinetd.d/amandaidx #保证display项为no 显示如下:
#default: off
#description: Part of the Amanda server package
service amandaidx{
socket_type = stream
protocol = tcp
wait = no
user = amanda
group = disk
server = /usr/lib/amanda/amindexd
disable = no
}
-
-
-
- #vim /etc/xinetd.d/amidxtape #保证diplay项为no 显示如下:
#default: off
#
# description: Part of the amanda server package
service amidxtape
{ socket_type = stream
protocol = tcp
wait = no
user = amanda
group = disk
server = /usr/lib/amanda/amidxtaped
disable = no
}
-
完成后重启超级守护进程xinetd
-
配置服务端验证客户端文件.amandahosts
-
- # vim /var/lib/amanda/.amandahosts #显示如下:
client root
-
- # vi /etc/amanda/DailySet1/amanda.conf #查找以下相应项,并进行修改
org "server" //设置使用amanda的单位或者机构的名称
mailto "root@localhost"//指定将报告发送的邮件地址
dumpuser amanda //指定使用Amanda备份的用户,默认为amanda用户
dumpcycle 7days //设置备份周期的长度,单位也可以是weeks,在这里设置7days和1weeks的效果是一样的。
runspercycle 8 //设置每个备份周期内amanda运行的次数
tapetype HARD-DISK //设置存储类型
labelstr "^DailySet1-[0-9][0-9]*$"//定义卷标格式
logdir "/var/log/amanda" //指定日志存放路径,默认存放在amanda配置目录下
tpchanger "chg-disk" //更换磁带的脚本
changerfile "/etc/amanda/DailySet1/changer"
tapedev "file:/amanda/DailySet1" //指定存储位置
define dumptype root-tar { //定义转存储类
global //调用前面定义的global类型
program "GNUTAR" //使用GNU tar作为备份程序,默认是DUMP
comment "root partitions dumped with tar" //描述该类型的信息
compress none //不采用压缩index yes //备份集索,必须为yes(默认为no),否则在恢复的时候将不能找到可恢复的索引信息
priority low
}
define tapetype HARD-DISK { //定义磁盘类型
comment "disk-to-disk"
length 1000 mbytes
}
slot_root_dir -|
|- info
|- data >slot1/
|- slot1/
|- slot2/
|- ...
#mkdir -p /amanda/DailySet1 #amanda.conf中tapedev项
#cd /amanda/DailySet1
#mkdir slot1 slot2 slot3 slot4 slot5 slot6 slot7 slot8 #创建slot,数量与 amanda中tapecycle 8 tapes,数目一致,要大于runcycle的数值
#touch info #创建info文件
#ln -s slot1 data #创建 链接文件
#chown amanda.disk /amanda #更改目录属主,备份时使用amanda用户,必须使其有权限
-
添加备份项,这里备份192.168.4.138上的/data目录
-
- #vim /etc/amanda/DailySet1/disklist
client /data comp-root-tar #最后一行注释掉
#touch /etc/amanda/DailySet1/tapelist
#chown amanda.disk /etc/amanda/DailySet1/tapelist
-
制作虚拟磁盘卷标 与使用磁带机一样,使用前也需要为虚拟磁盘创建卷标
# su - amanda
$ /usr/sbin/amlabel DailySet1 DailySet1-01 slot 1 #若成功则显示如下,其它省略
changer: got exit: 0 str: 1 file:/amanda/Dailyset1
labeling tape in slot 1 (file:/amanda/Dailyset1):
rewinding, reading label, not an amanda tape (Read 0 bytes)
rewinding, writing label DailySet1-01, checking label, done.
$for((i=2;i<=8;i++));do /usr/sbin/amlabel DailySet1 DailySet1-0$i slot $i;done
-
建立curinfo和index目录或文件 #与amanda.config文件定义有关
# mkdir -p /etc/amanda/DailySet1/curinfo/client/_var_log
# tuoch /etc/amanda/DailySet1/curinfo/client/_var_log/info
#mkdir /etc/amanda/DailySet1/curinfo/client/_data
#touch /etc/amanda/DailySet1/curinfo/client/_data/info
# mkdir -p /etc/amanda/DailySet1/index/client/_var_log
#mkdir /etc/amanda/DailySet1/index/client/_data
# chown -R amanda.disk /etc/amanda/DailySet1/curinfo #权限更改很重要
# chown -R amanda.disk /etc/amanda/DailySet1/index
-
创建holding disk位置,amanda.conf文件需求
#mkdir /dumps/amanda
#chown -R amanda.disk /dumps
配置测试
测试使用的命令为amcheck,必须su到amanda用户
#su - amanda
$ /usr/sbin/amcheck DailySet1 #默认检查选项cs
Amanda Tape Server Host Check
-----------------------------
Holding disk /dumps/amanda: 188781820 KB disk space available, using 188679420 KB
slot 1: read label `DailySet1-01', date `X'
NOTE: skipping tape-writable test
Tape DailySet1-01 label ok
Server check took 0.105 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 1 host checked in 0.000 seconds, 0 problems found
(brought to you by Amanda 2.5.0p2)
显示如上则表示配置无误
附:amcheck命令选项
amcheck(su - amanda)默认时为-cs
-s 检测服务端状态及磁带状态
-c 检测客户端状态
-l 服务端测试
-t 服务端tape测
-m 有错误时发送mail 给用户(mailto)
-a 发送mail给用户
-M
+mailadderss
需求测试
#su - amanda
$/usr/sbin/amdump DailySet1 #按照DailySet1设置备份数据
$cat /etc/amanda/DailySet1/log.20100930.0 #备份完成无提示,可以查看日志文件
DISK planner client /data
START planner date 20100930
START driver date 20100930
STATS driver startup time 0.039
FINISH planner date 20100930 time 0.127
START taper datestamp 20100930 label DailySet1-01 tape 0
SUCCESS dumper client /data 20100930 1 [sec 0.025 kb 34 kps 1320.9 orig-kb 100]
SUCCESS chunker client /data 20100930 1 [sec 0.061 kb 34 kps 1070.8]
SUCCESS taper client /data 20100930 1 [sec 0.002 kb 96 kps 41308.1 {wr: writers 3 rdwait 0.000 wrwait 0.000 filemark 0.000}]
INFO taper tape DailySet1-01 kb 96 fm 1 [OK]
FINISH driver date 20100930 time 0.365
# crontab -u amanda -e #如下:
* 1 * * * /usr/local/sbin/amdump DailySet1
附:amdump命令及amcleanup命令
amdump
amdump config [host[disk...]...] 一般放在cron周期事务中
example:
runs amdump every weeknight at 1 a.m. as user bin:
0 1 * * 1-5 bin /usr/local/sbin/amdump daily #daily为配置名称
注意两点:
1、waiting for hold file to be removed
2、amdump or amflush is already running, or you must run amcleanup
amcleanup
amcleanup 可以产生amanda的邮件报告并且在客户机在备份到tape server失败后,更新amanda的数据库。
amdump进程一般会在amdump之前自动运行,但是有时amdump不能使它运行,这时需要手动运行。
在备份机宕机后,我们应该在系统启动中使用amcleanup命令。我们可以将命令放到/etc/rc.local文件中
/usr/local/sbin/amcleanup daily
如果一切正常(amcleanup done nothing)会出现下面的提示:
amcleanup: no unprocessed logfile to clean up
-
- 还原时使用的是client,必须使用root用户进行还原,而且我们选择进入到需要还原的目录下,这样我们不用再进行备份地址的选择。
[root@client data]# amrecover DailySet1 -s server -t server #-s是指定索引的主机名 -t 指定备份机的主机名 (IP也可以)
-
-
如果配置正常的话则会自动进行还原数据。以下是手动还原的方法:
amrecover> listdisk #查看磁盘
200- List of disk for host client
201- /data
200 List of disk for host client
amrecover> setdisk /data #选择磁盘
200 Disk set to /data.
amrecover>
amrecover> setdate 2010-09-30 #选择日期
200 Working date set to 2010-09-30.
amrecover> ls #列出备份过的文件
2010-09-30 yum.conf
2010-09-30 yp.conf
2010-09-30 xinetd.conf
2010-09-30 rwtab
2010-09-30 rpc
--More--
amrecover>add yum.conf #增加还原内容 yum.conf add / 为还原全部内容到/data目录
Added /yum.conf
amrecover> add xinetd.conf #增加还原内容 xinetd.conf
Added /xinetd.conf
amrecover>extract #取出 这两个文件
Extracting files using tape drive null: on host 192.168.4.142.
The following tapes are needed: DailySet1-08
Restoring files into directory /data
Continue [?/Y/n]? Y
Extracting files using tape drive null: on host 192.168.4.142.
Load tape DailySet1-08 now
Continue [?/Y/n/s/t]? Y
./xinetd.conf
./yum.conf
amrecover>
-
amrecover> quit
200 Good bye.
[ root@client data]# ll
total 16
-rw-r--r-- 1 root root 1001 Oct 8 14:31 xinetd.conf
-rw-r--r-- 1 root root 333 Oct 8 14:31 yum.conf
[root@client data]#
amadmin工具
(下面英文较多,自己看)
amadmin 控制amanda备份的管理接口 配置文件configAmanda
amadmin config command [commandoptions]
如果disklist文件中没有指定磁盘时,命令中将需要指定 hostname [disks]
【Both hostname anddisks are special expressions, see the "HOST & DISK EXPRESSION" section of amanda(8) for a description.】
@force-bump [ hostname [ disks ]* ]+ 强制hostname上的disk 在下一次amanda运行时使用增量备份
@force-no-bump [ hostname [ disks ]* ]+ 强制hostname上的disk 不在下一次amanda运行时使用增量备份
@unforce-bump [ hostname [ disks ]* ]+ 不使用force-bump 或force-no-bump 命令
@force [ hostname [ disks ]* ]+ 强制hostname上的disk 在下一次amanda运行时使用完全(level 0)备份
@unforce [ hostname [ disks ]* ]+ 不使用强制命令
@reuse tapelabel [ ... ] 在它们周期结束后重新使用tape
@no-reuse tapelabel [ ... ] 在它们周期结束后不重新使用tape,如果tape用尽,amanda则请求新的tape并使计数正确。
@due [ hostname [ disks ]* ]* 查看下一次完全备份的时间
@ find [ --sort hkdlpb ] [ hostname [ disks ]* ]*
Display all backups currently on tape or in the holding disk. The tape label or holding disk filename, file number, andstatus are displayed.
The --sort option changes the sort order using the following
flags:
h host name k disk name d dump date l backup level p dump part b tape label 。An uppercase letter reverses the sort order for that key. The default sort order is hkdlpb.
@delete [ hostname [ disks ]* ]+ 删除disk 如果没有从disklist中去掉disk,则下一次运行时amanda将认为它是一个新的disk
@bumpsize 显示当前预先预留的全部备份等级的入口参数
@balance [ --days <num> ] 显示分配的备份时间表
@export [ hostname [ disks ]* ]* 将amanda中的数据记录转换为文本格式,用于将该文件传送到另外的amanda服务器并输入
@ import amanda数据库的导入(参照export)
@disklist [ hostname [ disks ]* ]* 显示所有在hostname中的disk的信息。通常用作查找调试debug
@info [ hostname [ disks ]* ]* 显示所有在hostname中的disk的amanda数据库的记录信息。通常用作调试debug
EXAMPLES(示例)
Request three specific file systems on machine-a get a full level 0
backup during the next Amanda run.
$ amadmin daily force machine-a / /var /usr
amadmin: machine-a:/ is set to a forced level 0 tonight.
amadmin: machine-a:/var is set to a forced level 0 tonight.
amadmin: machine-a:/usr is set to a forced level 0 tonight.
Request all file systems on machine-b get a full level 0 backup dur-
ing the next Amanda run.
$ amadmin daily force machine-b
amadmin: machine-b:/ is set to a forced level 0 tonight.
amadmin: machine-b:/var is set to a forced level 0 tonight.
amadmin: machine-b:/usr is set to a forced level 0 tonight.
amadmin: machine-b:/home is set to a forced level 0 tonight.
Undo the previous force request for /home on machine-b. The other
file systems will still get a full level 0 backup.
$ amadmin daily unforce machine-b /home
amadmin: force command for machine-b:/home cleared.
Locate backup images of /var from machine-c. The tape or file column
displays either a tape label or a filename depending on whether the
image is on tape or is still in the holding disk. If the image is on
tape, the file column tells you which file on the tape has the image
(file number zero is a tape label). This column shows zero and is
not meaningful if the image is still in the holding disk. The status
column tells you whether the backup was successful or had some type
of error.
$ amadmin daily find machine-c /var
date host disk lv tape or file file part status
2000-11-09 machine-c /var 0 000110 9 -- OK
2000-11-08 machine-c /var 2 000109 2 -- OK
2000-11-07 machine-c /var 2 /amanda/20001107/machine-c._var.2 0 OK
2000-11-06 machine-c /var 2 000107 2 -- OK
2000-11-05 machine-c /var 2 000106 3 -- OK
that may be transmitted to another Amanda machine and
imported.
import Convert exported records read from standard input to a form
Amanda uses and insert them into the database on this
machine.
disklist [ hostname [ disks ]* ]*
Display the disklist information for each of the disks on
hostname (or all hosts). Mostly used for debugging.
info [ hostname [ disks ]* ]*
Display the database record for each of the disks on hostname
(or all hosts). Mostly used for debugging.
EXAMPLES
Request three specific file systems on machine-a get a full level 0
backup during the next Amanda run.
$ amadmin daily force machine-a / /var /usr
amadmin: machine-a:/ is set to a forced level 0 tonight.
amadmin: machine-a:/var is set to a forced level 0 tonight.
amadmin: machine-a:/usr is set to a forced level 0 tonight.
Request all file systems on machine-b get a full level 0 backup dur-
ing the next Amanda run.
$ amadmin daily force machine-b
amadmin: machine-b:/ is set to a forced level 0 tonight.
amadmin: machine-b:/var is set to a forced level 0 tonight.
amadmin: machine-b:/usr is set to a forced level 0 tonight.
amadmin: machine-b:/home is set to a forced level 0 tonight.
Undo the previous force request for /home on machine-b. The other
file systems will still get a full level 0 backup.
$ amadmin daily unforce machine-b /home
amadmin: force command for machine-b:/home cleared.
Locate backup images of /var from machine-c. The tape or file column
displays either a tape label or a filename depending on whether the
image is on tape or is still in the holding disk. If the image is on
tape, the file column tells you which file on the tape has the image
(file number zero is a tape label). This column shows zero and is
not meaningful if the image is still in the holding disk. The status
column tells you whether the backup was successful or had some type
of error.
$ amadmin daily find machine-c /var
date host disk lv tape or file file part status
2000-11-09 machine-c /var 0 000110 9 -- OK
2000-11-08 machine-c /var 2 000109 2 -- OK
2000-11-07 machine-c /var 2 /amanda/20001107/machine-c._var.2 0 OK
2000-11-06 machine-c /var 2 000107 2 -- OK
2000-11-05 machine-c /var 2 000106 3 -- OK
2000-11-04 machine-c /var 2 000105 2 -- OK
2000-11-03 machine-c /var 2 000104 2 -- OK
2000-11-02 machine-c /var 2 000103 2 -- OK
2000-11-01 machine-c /var 1 000102 5 -- OK
2000-10-31 machine-c /var 1 000101 3 -- OK
Forget about the /workspace disk on machine-d. If you do not also
remove the disk from the disklist file, Amanda will treat it as a
new disk during the next run.
$ amadmin daily delete machine-d /workspace
amadmin: machine-d:/workspace deleted from database.
amadmin: NOTE: you?.l have to remove these from the disklist yourself.
Find the next tape Amanda will use (in this case, 123456).
$ amadmin daily tape
The next Amanda run should go onto tape 123456 or a new tape.
Show how well full backups are balanced across the dump cycle. The
due-date column is the day the backups are due for a full backup.
#fs shows the number of filesystems doing full backups that night,
and orig KB and out KB show the estimated total size of the backups
before and after any compression, respectively.
The balance column shows how far off that night?. backups are from
the average size (shown at the bottom of the balance column).
Amanda tries to keep the backups within +/- 5%, but since the amount
of data on each filesystem is always changing, and Amanda will never
delay backups just to rebalance the schedule, it is common for the
schedule to fluctuate by larger percentages. In particular, in the
case of a tape or backup failure, a bump will occur the following
night, which will not be smoothed out until the next pass through
the schedule.
The last line also shows an estimate of how many Amanda runs will be
made between full backups for a file system. In the example, a file
system will probably have a full backup done every eight times
Amanda is run (e.g. every eight days).
$ amadmin daily balance
due-date #fs orig KB out KB balance
-------------------------------------------
The last line also shows an estimate of how many Amanda runs will be
The last line also shows an estimate of how many Amanda runs will be
made between full backups for a file system. In the example, a file
system will probably have a full backup done every eight times
Amanda is run (e.g. every eight days).
$ amadmin daily balance
due-date #fs orig KB out KB balance
-------------------------------------------
11/10 Mon 21 930389 768753 +5.1%
11/11 Tue 29 1236272 733211 +0.2%
11/12 Wed 31 1552381 735796 +0.6%
11/13 Thu 23 1368447 684552 -6.4%
11/14 Fri 32 1065603 758155 +3.6%
11/15 Sat 14 1300535 738430 +0.9%
11/16 Sun 31 1362696 740365 +1.2%
11/17 Mon 30 1427936 773397 +5.7%
11/18 Tue 11 1059191 721786 -1.3%
11/19 Wed 19 1108737 661867 -9.5%
-------------------------------------------
TOTAL 241 12412187 7316312 731631 (estimated 8 runs per dumpcycle)
FILES
/usr/local/etc/amanda/config/amanda.conf