1.启动
首先必须启动MySQL和bacule。
shell> mysqld_safe --user=mysql & shell> cd /root/bacula/bin shell> ./bacula start shell> ./bconsole
bacula脚本会开启dir、fd和sd,然后启动console连接到dir,console用来与dir通信、查询状态和运行作业。这时会打印如下信息,*表示命令提示符。
1000 OK: fubuntu-dir Version: 5.0.3 (04 August 2010)
Enter a period to cancel a command.
*
输入help命令可以得到帮助信息。
2.运行一个备份作业
bacula的配置文件主要包括四个:bacula-dir.conf,bacula- fd.conf,bacula-sd.conf和bconsole.conf,其中bacula-dir.conf定义了各种资源,包括Storage、 Client、FileSet、Job、Schedule等等,可以使用show命令来查看各种资源的信息,也可以用status命令查看 director、storage和client的状态。FileSet是定义的文件集,Schedule是定义的备份策略,而Job是定义的作业,以下 是从默认配置文件bacula-dir.conf中摘下来的例子。
Name = "DefaultJob"
Type = Backup
Level = Incremental
Client = localhost.localdomain-fd
FileSet = "Full Set"
Schedule = "WeeklyCycle"
Storage = File
Messages = Standard
Pool = File
Priority = 10
Write Bootstrap = "/root/bacula/bin/working/%c.bsr"
}
#
# Define the main nightly save backup job
# By default, this job will back up to disk in /tmp
Job {
Name = "BackupClient1"
JobDefs = "DefaultJob"
}
# List of files to be backed up
FileSet {
Name = "Full Set"
Include {
Options {
signature = MD5
}
#
# Put your list of files here, preceded by 'File =', one per line
# or include an external list with:
#
# File = <file-name
#
# Note: / backs up everything on the root partition.
# if you have other partitions such as /usr or /home
# you will probably want to add them too.
#
# By default this is defined to point to the Bacula binary
# directory to give a reasonable FileSet to backup to
# disk storage during initial testing.
#
File = /root/bacula/bin
}
#
# If you backup the root directory, the following two excluded
# files can be useful
#
Exclude {
File = /root/bacula/bin/working
File = /tmp
File = /proc
File = /tmp
File = /.journal
File = /.fsck
}
}
#
# When to do the backups, full backup on first sunday of the month,
# differential (i.e. incremental since full) every other sunday,
# and incremental backups other days
Schedule {
Name = "WeeklyCycle"
Run = Full 1st sun at 23:05
Run = Differential 2nd-5th sun at 23:05
Run = Incremental mon-sat at 23:05
}
可以看到bacula-dir.conf首先定义了一个默认作业JobDefs,然后再使用JobDefs定义了一个Job,这里JobDefs类似一个模板,可以在定义Job时对各个资源进行修改。默认作业备份的文件集是"Full Set",备份策略是"WeeklyCycle"。这些都在下面都给出了定义,"Full Set"文件集包括了/ root / bacula / bin目录下的文件,而"WeeklyCycle"策略的内容是第一个周日进行全量备份,第二到第五个周日进行差量备份,每个周一到周六进行增量备份。
使用run命令来运行BackupClient1这个作业。这时会有信息,提示请使用label命令创建一个新卷。这时可以先使用status命令可以查看作业的状态,显示正在等待一个卷。
(...)
Running Jobs:
Console connected at 24-Aug-11 14:59
JobId Level Name Status
======================================================================
3 Full BackupClient1.2011-08-24_15.53.55_08 is waiting for an appendable Volume
====
使用label命令创建一个新卷,注意选择Pool时一定要和定义作业时一致,也就是选择File。创建成功后,在/tmp目录下会出现卷文件,作业会继续运行,当运行结束会打印新的信息。
24-Aug 16:15 localhost.localdomain-sd JobId 3: Job write elapsed time = 00:00:01, Transfer rate = 11.94 M Bytes/second
24-Aug 16:15 localhost.localdomain-dir JobId 3: Bacula localhost.localdomain-dir 5.0.3 (04Aug10): 24-Aug-2011 16:15:25
Build OS: i686-pc-linux-gnu redhat Enterprise release
JobId: 3
Job: BackupClient1.2011-08-24_15.53.55_08
Backup Level: Full (upgraded from Incremental)
Client: "localhost.localdomain-fd" 5.0.3 (04Aug10) i686-pc-linux-gnu,redhat,Enterprise release
FileSet: "Full Set" 2011-08-24 11:30:35
Pool: "File" (From Job resource)
Catalog: "MyCatalog" (From Client resource)
Storage: "File" (From Job resource)
Scheduled time: 24-Aug-2011 15:53:50
Start time: 24-Aug-2011 15:53:57
End time: 24-Aug-2011 16:15:25
Elapsed time: 21 mins 28 secs
Priority: 10
FD Files Written: 45
SD Files Written: 45
FD Bytes Written: 11,935,432 (11.93 MB)
SD Bytes Written: 11,940,492 (11.94 MB)
Rate: 9.3 KB/s
Software Compression: None
VSS: no
Encryption: no
Accurate: no
Volume name(s): TestVolume002
Volume Session Id: 3
Volume Session Time: 1314198156
Last Volume Bytes: 11,951,479 (11.95 MB)
Non-fatal FD errors: 0
SD Errors: 0
FD termination status: OK
SD termination status: OK
Termination: Backup OK
24-Aug 16:15 localhost.localdomain-dir JobId 3: Begin pruning Jobs older than 6 months .
24-Aug 16:15 localhost.localdomain-dir JobId 3: No Jobs found to prune.
24-Aug 16:15 localhost.localdomain-dir JobId 3: Begin pruning Jobs.
24-Aug 16:15 localhost.localdomain-dir JobId 3: No Files found to prune.
24-Aug 16:15 localhost.localdomain-dir JobId 3: End auto prune.
从最后的几行信息和配置文件中Pool资源的定义可以看出,作业是有保留期限的,File Pool的保留期限是365天。
如果每一个Bacula要使用的卷都需要我们手动label,的确有点麻烦,不过只有在使用磁带卷时才需要这样,而像我们刚才使用的磁盘卷,Bacula是可以自动进行label的。
想要删除测试数据的话,就将/tmp目录下的卷直接删除,再使用drop_mysql_tables和make_mysql_tables脚本。
3.恢复
想要恢复刚才备份的文件集,可以使用restore all命令,然后选择"5: Select the most recent backup for a client"。由于目前只配置了一个客户端,并只有一次备份作业,所以bacula会自动选择。比较有意思的是,bacula选择好备份作业后,会在内 存中建一个目录树并将作业里的所有文件插入到树中,然后进入文件选择模式,可以使用cd、ls命令查看哪些文件会被恢复。
remove (unmark) files to be restored. No files are initially added, unless
you used the "all" keyword on the command line.
Enter "done" to leave this mode.
cwd is: /
$ ls
root/
$ cd root
cwd is: /root/
$ ls
bacula/
$ cd bacula
cwd is: /root/bacula/
$ ls
*bin/
$ cd bin
cwd is: /root/bacula/bin/
确定了要恢复的文件后,使用done退出文件选择模式,输入yes恢复就开始了,文件会被恢复到/tmp/bacula-restores目录。