六、bacula恢复文件
[root@balucaclient etc]# rm -rf /home/mazentop.com/* #删除fd中所有文件
[root@baculaserver etc]# ./bconsole
Connecting to Director 192.168.1.10:9101
1000 OK: baculaserver-dir Version: 5.2.10 (28 June 2012)
Enter a period to cancel a command.
*restore
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.
To select the JobIds, you have the following choices:
1: List last 20 Jobs run
2: List Jobs where a given File is saved
3: Enter list of comma separated JobIds to select
4: Enter SQL list command
5: Select the most recent backup for a client
6: Select backup for a client before a specified time
7: Enter a list of files to restore
8: Enter a list of files to restore before a specified time
9: Find the JobIds of the most recent backup for a client
10: Find the JobIds for a backup for a client before a specified time
11: Enter a list of directories to restore for found JobIds
12: Select full restore to a specified Job date
13: Cancel
Select item: (1-13): 3
Enter JobId(s), comma separated, to restore: 1,3
You have selected the following JobIds: 1,3
#从备份状态看,JobID为1的为完全备份,JobID为3的为差异备份,因此只需恢复jobid为1和3的备份即可完全恢复,要还有增量的备份,也要把增量的Jobid也写上。
Building directory tree for JobId(s) 1,3 ...
3 files inserted into the tree.
You are now entering file selection mode where you add (mark) and
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: /
$ cd home/mazentop #使用?查看可以使用的命令,可以cd到下级目录,只恢复特定的文件
$ mark * #指定要恢复的文件或目录,* 表所有,要是恢复特定文件,mark 接文件
2488 files marked.
$ done
Storage "" not found, using Storage "192.168.1.11_web_storage" from MediaType "File".
Bootstrap records written to /usr/local/bacula/var/bacula/working/baculaserver-dir.restore.1.bsr
The job will require the following
Volume(s) Storage(s) SD Device(s)
===========================================================================
2012-12-14-1 192.168.1.11_web_storage 192.168.1.11_web_dev 2012-12-14-3 192.168.1.11_web_storage 192.168.1.11_web_dev
Volumes marked with "*" are online.
2488 files selected to be restored.
The defined Restore Job resources are:
1: Restore_192.168.1.11_web_job
2: Restore_192.168.1.11_database_job
3: Restore_192.168.1.12_web_job
4: Restore_192.168.1.12_database_job
Select Restore Job (1-4): 1 #选择1
Defined Clients:
1: 192.168.1.11-fd
2: 192.168.1.12-fd
Select the Client (1-2): 1 #选择1
Run Restore job
JobName: Restore_192.168.1.11_web_job
Bootstrap: /usr/local/bacula//baculaserver-dir.restore.2.bsr
Where: /bacula-restores
Replace: always
FileSet: web_fileset
Backup Client: 192.168.1.11-fd
Restore Client: 192.168.1.11-fd
Storage: 192.168.1.11_web_storage
When: 2012-12-14 9:09:44
Catalog: MyCatalog
Priority: 10
Plugin Options: *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=4
[root@balucaclient etc]# ls /home/mazentop.com/
#查看fd端,显示已经完全恢复
另一种方法恢复指定文件
[root@balucaclient etc]# rm -rf /home/mazentop.com/public_html/index2.html
[root@baculaserver etc]# ./bconsole
*restore
First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.
To select the JobIds, you have the following choices:
1: List last 20 Jobs run
2: List Jobs where a given File is saved
3: Enter list of comma separated JobIds to select
4: Enter SQL list command
5: Select the most recent backup for a client
6: Select backup for a client before a specified time
7: Enter a list of files to restore
8: Enter a list of files to restore before a specified time
9: Find the JobIds of the most recent backup for a client
10: Find the JobIds for a backup for a client before a specified time
11: Enter a list of directories to restore for found JobIds
12: Select full restore to a specified Job date
13: Cancel
Select item: (1-13): 7 #7表示恢复指定的文件
Defined Clients:
1: 192.168.1.11-fd
2: 192.168.1.12-fd
Select the Client (1-2): 1
Enter file names with paths, or < to enter a filename
containing a list of file names with paths, and terminate
them with a blank line.
Enter full filename: /home/mazentop/public_html/index2.html #指定恢复index2.html文件
Enter full filename:
Storage "" not found, using Storage "192.168.1.11_web_storage" from MediaType "File".
Bootstrap records written to /usr/local/bacula/var/bacula/working/baculaserver-dir.restore.2.bsr
The job will require the following
Volume(s) Storage(s) SD Device(s)
===========================================================================
2012-12-14-3
Volumes marked with "*" are online.
1 file selected to be restored.
Run Restore job
JobName: Restoreweb
Bootstrap: /usr/local/bacula/var/bacula/working/baculaserver-dir.restore.2.bsr
Where: *None*
Replace: always
FileSet: web_fileset
Backup Client: 192.168.1.11-fd
Restore Client: 192.168.1.11-fd
Storage: 192.168.1.11_web_storage
When: 2012-12-14 09:13:19
Catalog: MyCatalog
Priority: 10
Plugin Options: *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=5
[root@balucaclient etc]# ls /home/mazentop/public_html
index2.html
#显示fd上index2.html成功恢复
七、bconsole中相关命名说明1. status 查看director、client、storage 状态。
[root@baculaserver etc]# ./bconsole
Connecting to Director 192.168.1.10:9101
1000 OK: baculaserver-dir Version: 5.2.10 (28 June 2012)
Enter a period to cancel a command.
*status
Status available for:
1: Director
2: Storage
3: Client
4: All
Select daemon type for status (1-4): 3
The defined Client resources are:
1: 192.168.1.11-fd
2: 192.168.1.12-fd
Select Client (File daemon) resource (1-2): 1
Connecting to Client 192.168.1.11-fd at 192.168.1.11:9102
2012-02-15-fd Version: 5.2.10 (28 June 2012) i686-pc-linux-gnu
RedHat Enterprise release
Daemon started 14- 1212 09:16, 6 Jobs run since started.
Heap: heap=516,096 smbytes=81,546 max_bytes=154,559 bufs=68 max_bufs=95
Sizeof: boffset_t=8 size_t=4 debug=0 trace=0
Running Jobs:
Director connected at: 14- 1212 09:16
No Jobs running.
====
Terminated Jobs:
Terminated Jobs:
JobId Level Files Bytes Status Finished Name
======================================================================
1 Full 2,400 97.14 M OK 14-Dec-12 08:57 192.168.1.11_web_job
2 Incr 88 10 M OK 14-Dec-12 08:58 192.168.1.11_web_job
3 Diff 100 14 M OK 14-Dec-12 08:59 192.168.1.11_web_job
4 2,488 121.14 M OK 14-Dec-12 09.09 Restore_192.168.1.11_web_job
====
也可以
status dir 查看director 的状态
status client 查看 client 的状态
status storage 查看 storage 的状态
2. show 查看资源信息。
pools filesets clients storages schedule jobs message
3. list llist
list pools | jobs | jobtotals | media <pool=pool-name> | files <jobid=nn>
4. run 手动运行一次编好的任务。
5. reload 从新载入配置文件(当修改配置文件后用这个,不需要停止服务)
6. estimate 对某次任务进行评估。它会连接到客户端,并输出这次任务的fileset 中 文件数,和这次备份任务所占的空间。
7. purge prune
一般不会用到,我们设定的是过期自动清除。
purge 危险!!!!! 这是一个危险命令。他能清除一个客户端的所有备份任务,文件,和卷。
prune 这个命令和 purge 相似,但安全很多,它只会清除过期的文件,任务,和卷。
8. time 查看时间。
9. delete 删除volume , pool 或某次任务。
10. disable 和 enable 是一对,它可以禁止和启用某个任务。
11 cancel 取消一次正在运行的任务。例如:某次任务由于设置不当,卡住不动了,我们就可以使用这条命令,去取消这次任务。
cancel 20 取消任务ID=20 的任务。
12 update 修改 volumes ,pool 参数。
此实例并不是我在真实环境上的IP,也许有漏改的地方,欢迎指正。一般服务器都有两个网卡,一个接内网,一个接公网,若要备份的FD有内网,而且与DIR和SD所在的服务器能用内网连通,那请尽量使用内网备份,若没有内网,则只能使用公网IP进行备份,Client和Storage的对应IP都要写成外网IP。若将SD布署到另一台服务器上,也是可以的,只需要将bacula安装到SD服务器上(安装方法与安装baculaserver相同),只是只在SD服务器上配置bacula-sd.conf这个文件,当然多SD也是可以实现的,但最好在bacula-sd.conf文件的Storage段中添加SDAddress = 116.204.96.213,如下
Storage { # definition of myself
Name = hk02.mazentop.com-sd
SDPort = 9103 # Director's port
WorkingDirectory = "/usr/local/bacula/"
Pid Directory = "/usr/local/bacula/bin/working"
Maximum Concurrent Jobs = 20
SDAddress = 116.204.96.213 #添加这行
}
但多SD布署时,应该一开始就布署好,本人亲测,在后来再添加另一个SD不成功。
写了一个脚本,可以将备份的状态以网页的形式来查看:
#!/bin/bash
egrep 'JobId:|Job:|Backup Level:|End time:|SD Files Written:|Last Volume Bytes:|Termination:' /usr/local/bacula/log |awk -F": " '{print $2}' |awk 'NR%7==1 {print $1} NR%7==2
{gsub(/_/,"-",$0);gsub(/database/,"db",$0);print $1} NR%7==3 {gsub(/Differential,/,"Diff",$0);gsub(/Incremental,/,"Incr",$0);print $1} NR%7==4 {sub(/ 1月/,"01",$0);sub(/ 2月/,"
02",$0);sub(/ 3月/,"03",$0);sub(/ 4月/,"04",$0);sub(/ 5月/,"05",$0);sub(/ 6月/,"06",$0);sub(/ 7月/,"07",$0);sub(/ 8月/,"08",$0);sub(/ 9月/,"09",$0);sub(/10月/,"10",$0);sub(/11>
月/,"11",$0);sub(/12月/,"12",$0);print $1"-"$2} NR%7==5 {print $0} NR%7==6 {sub(/\(/,"",$0);sub(/\)/,"",$0);print $2$3} NR%7==0 {sub(/Backup Error/,"Error",$0);sub(/Canceled/,"
Cance",$0);print $2}' |awk -F"-" 'NR%7==2 {print $1"-"$2} NR%7==4 {print $3"-"$2"-"$1" "$4} NR%7!=2 && NR%7!=4 {print $0}'|awk 'NR%7==1 {printf $0"\t"} NR%7==2 {printf $0"\t"}
NR%7==3 {printf $0"\t"} NR%7==4 {printf $0"\t"} NR%7==5 {printf $0"\t"} NR%7==6 {printf $0"\t"} NR%7==0 {printf $0"\n"}' |awk -F"\t" '{print $1"\t"$2" \t"$3"\t"$7"\t "$4"\t"
$6"\t"$5}' |sort -nr |awk 'BEGIN {print "\nJobId\tJobname\t\t\tLevel\tStatus\t Finishedtime\t\tBytes\t Files\n=============================================================
========================================="} {print $0} END {print "=====================================================================================================\nJobId\
tJobname\t\t\tLevel\tStatus\t Finishedtime\t\tBytes\t Files\n"}' > /home/janus2.mazentop.com/public_html/backup #这个是网站的家目录,然后将这个脚本写在crontab中执行,然后输入你定义的访问url就可以了。若是像我们公司备份的服务器太多,要是完全显示的话,就会很多,我只显示两天,脚本如下:
#!/bin/bash
egrep 'JobId:|Job:|Backup Level:|End time:|SD Files Written:|Last Volume Bytes:|Termination:' /usr/local/bacula/log |awk -F": " '{print $2}' |awk 'NR%7==1 {print $1} NR%7==2
{gsub(/_/,"-",$0);gsub(/database/,"db",$0);print $1} NR%7==3 {gsub(/Differential,/,"Diff",$0);gsub(/Incremental,/,"Incr",$0);print $1} NR%7==4 {sub(/ 1月/,"01",$0);sub(/ 2月/,"
02",$0);sub(/ 3月/,"03",$0);sub(/ 4月/,"04",$0);sub(/ 5月/,"05",$0);sub(/ 6月/,"06",$0);sub(/ 7月/,"07",$0);sub(/ 8月/,"08",$0);sub(/ 9月/,"09",$0);sub(/10月/,"10",$0);sub(/11>
月/,"11",$0);sub(/12月/,"12",$0);print $1"-"$2} NR%7==5 {print $0} NR%7==6 {sub(/\(/,"",$0);sub(/\)/,"",$0);print $2$3} NR%7==0 {sub(/Backup Error/,"Error",$0);sub(/Canceled/,"
Cance",$0);print $2}' |awk -F"-" 'NR%7==2 {print $1"-"$2} NR%7==4 {print $3"-"$2"-"$1" "$4} NR%7!=2 && NR%7!=4 {print $0}'|awk 'NR%7==1 {printf $0"\t"} NR%7==2 {printf $0"\t"}
NR%7==3 {printf $0"\t"} NR%7==4 {printf $0"\t"} NR%7==5 {printf $0"\t"} NR%7==6 {printf $0"\t"} NR%7==0 {printf $0"\n"}' |awk -F"\t" '{print $1"\t"$2" \t"$3"\t"$7"\t "$4"\t"
$6"\t"$5}' |sort -nr |egrep "`date +%Y-%m-%d`|`date -d "-1 days" +%Y-%m-%d`" |awk 'BEGIN {print "<pre>\nJobId\tJobname\t\t\tLevel\tStatus\t Finishedtime\t\tBytes\t Files\n
======================================================================================================"} {print $0} END {print "================================================
=====================================================\nJobId\tJobname\t\t\tLevel\tStatus\t Finishedtime\t\tBytes\t Files\n</pre>"}' > /home/janus2.mazentop.com/public_html
/index.html
访问效果如下:
JobId Jobname Level Status Finishedtime Bytes Files
=====================================================================================================
280 50.23.166.164-db Incr OK 2012-12-14 00:21:18 11.47MB 62
279 50.23.166.163-web Incr OK 2012-12-14 00:18:26 622.7KB 238
278 50.23.166.163-db Incr OK 2012-12-14 00:08:05 8.064MB 45
277 50.23.166.162-web Incr OK 2012-12-14 00:06:05 70.78MB 5,404
276 50.23.166.162-db Incr OK 2012-12-14 00:00:51 47.68MB 4
275 67.228.83.36-web Full OK 2012-12-13 08:34:23 10.48GB 354,907
274 67.228.83.36-db Incr OK 2012-12-13 03:26:01 19.00MB 3
273 67.228.83.35-web Incr OK 2012-12-13 03:24:56 3.788MB 1,143
272 67.228.83.35-db Incr OK 2012-12-13 03:22:20 40.99MB 3
271 67.228.83.34-web Incr OK 2012-12-13 03:22:01 16.27MB 2,555
270 67.228.83.34-db Incr OK 2012-12-13 03:19:53 5.307MB 5