7.Bconsole操作
1. Bconsole操作
启动控制台
cd /usr/local/bacula/bin
./bconsole
*help
Command Description
======= ===========
add Add media to a pool
autodisplay Autodisplay console messages
automount Automount after label
cancel Cancel a job
create Create DB Pool from resource
delete Delete volume, pool or job
disable Disable a job, attributes batch process
enable Enable a job, attributes batch process
estimate Performs FileSet estimate, listing gives full listing #预算某个备份或恢复job
exit Terminate Bconsole session
gui Non-interactive gui mode
help Print help on specific command
label Label a tape
list List objects from catalog
llist Full or long list like list command
messages Display pending messages
memory Print current memory usage
mount Mount storage
prune Prune expired records from catalog #从目录中删除过期记录(清除6个月(默认)以上的备份)
purge Purge records from catalog #清除目录中的记录 (危险操作)
quit Terminate Bconsole session
query Query catalog
restore Restore files
relabel Relabel a tape
release Release storage
reload Reload conf file #当配置文件修改之后,重新加载配置文件
run Run a job
restart Restart a job
resume Resume a job
status Report status
stop Stop a job
setdebug Sets debug level
setbandwidth Sets bandwidth
snapshot Handle snapshots
setip Sets new client address -- if authorized
show Show resource records
sqlquery Use SQL to query catalog
time Print current time
trace Turn on/off trace to file
truncate Truncate one or more Volumes
unmount Unmount storage
umount Umount - for old-time Unix guys, see unmount
update Update volume, pool or stats
use Use catalog xxx
var Does variable expansion
version Print Director version
wait Wait until no jobs are running
When at a prompt, entering a period cancels the command.
1.1. 查看bacula版本
*version
server-dir Version: 7.4.7 (16 March 2017) x86_64-unknown-linux-gnu redhat
1.2. estimate
*estimate
The defined Job resources are:
1: client1-backup
2: client1-restores
Select Job resource (1-2): 1
Using Catalog "MyCatalog"
Connecting to Client client1-fd at 192.168.119.130:9102
2000 OK estimate files=29 bytes=2,569,048
1.3. label 初始化存储
(备份数据全部存储至新label中,已备份的任务建议不要操作)
*label
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
The defined Storage resources are:
1: File1
2: File2
Select Storage resource (1-2): 1 # 选择存储资源
Enter new Volume name: bk # 输入新的存储名
Defined Pools:
1: Default
2: File
3: Scratch
4: File-1
5: Pool1
6: pool1
Select the Pool (1-6): 6 # 选择Pool,根据实际情况填写
Connecting to Storage daemon File1 at 192.168.119.129:9103 ...
Sending label command for Volume "bk" Slot 0 ...
3000 OK label. VolBytes=187 VolABytes=0 VolType=1 Volume="bk" Device="FileChgr1-Dev1" (/data)
Catalog record for Volume "bk", Slot 0 successfully created.
Requesting to mount FileChgr1 ...
3906 File device ""FileChgr1-Dev1" (/data)" is always mounted.
1.4. run备份测试(一次全备)
*run
A job name must be specified.
The defined Job resources are:
1: client1-backup
2: client1-restores
Select Job resource (1-2): 1 #选择客户端
Run Backup job
JobName: client1-backup
Level: Incremental
Client: client1-fd
FileSet: FileSet1
Pool: pool1 (From Job resource)
Storage: File1 (From Job resource)
When: 2017-07-16 10:36:22
Priority: 10
OK to run? (yes/mod/no): mod #选择备份模式
Parameters to modify:
1: Level
2: Storage
3: Job
4: FileSet
5: Client
6: When
7: Priority
8: Pool
9: Plugin Options
Select parameter to modify (1-9): 1 #修改备份模式
Levels:
1: Full
2: Incremental
3: Differential
4: Since
5: VirtualFull
Select level (1-5): 1 #选择全备
Run Backup job
JobName: client1-backup
Level: Full
Client: client1-fd
FileSet: FileSet1
Pool: pool1 (From Job resource)
Storage: File1 (From Job resource)
When: 2017-07-16 10:36:22
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=106
You have messages.
1.5. status查看状态
*status
Status available for:
1: Director
2: Storage
3: Client
4: Scheduled
5: All
Select daemon type for status (1-5): 3
The defined Client resources are:
1: server-fd
2: client1-fd
Select Client (File daemon) resource (1-2): 2
Connecting to Client client1-fd at 192.168.119.130:9102
client-fd Version: 7.4.7 (16 March 2017) x86_64-unknown-linux-gnu redhat
Daemon started 16-Jul-17 09:05. Jobs: run=12 running=0.
Heap: heap=135,168 smbytes=298,089 max_bytes=898,791 bufs=86 max_bufs=149
Sizes: boffset_t=8 size_t=8 debug=0 trace=0 mode=0 bwlimit=0kB/s
Plugin: bpipe-fd.so
Running Jobs:
Director connected at: 16-Jul-17 10:39
No Jobs running.
====
Terminated Jobs:
JobId Level Files Bytes Status Finished Name
===================================================================
97 Full 29 231.1 K OK 16-Jul-17 09:30 client1-backup
98 Incr 2 80.74 K OK 16-Jul-17 09:35 client1-backup
99 Incr 3 81.83 K OK 16-Jul-17 09:45 client1-backup
100 Incr 3 82.64 K OK 16-Jul-17 09:55 client1-backup
101 Diff 3 82.99 K OK 16-Jul-17 10:00 client1-backup
102 Incr 2 83.30 K OK 16-Jul-17 10:05 client1-backup
103 Incr 3 84.23 K OK 16-Jul-17 10:15 client1-backup
104 Incr 6 86.74 K OK 16-Jul-17 10:25 client1-backup
105 Incr 2 85.98 K OK 16-Jul-17 10:35 client1-backup
106 Full 29 237.1 K OK 16-Jul-17 10:37 client1-backup
====
1.6. restore恢复操作
*restore
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 #列出最近运行的20个Job
2: List Jobs where a given File is saved # 列出备份文件的路径
3: Enter list of comma separated JobIds to select # 按照特定的Jobid还原
4: Enter SQL list command # 输入SQL语句
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 # 找到最近一次备份的Jobid
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): 9 #查看最近的一个备份点
Defined Clients:
1: client-fd
2: client1-fd
3: server-fd
4: sky-client-fd
Select the Client (1-4): 2
Automatically selected FileSet: FileSet1
+-------+-------+----------+----------+---------------------+--------------------------------+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
+-------+-------+----------+----------+---------------------+--------------------------------+
| 106 | F | 29 | 237,101 | 2017-07-16 10:37:01 | client1-backup-2017-07-16-id95 |
+-------+-------+----------+----------+---------------------+--------------------------------+
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): 5 #恢复测试,选择最近的一个备份点
Defined Clients:
1: client-fd
2: client1-fd
3: server-fd
4: sky-client-fd
Select the Client (1-4): 2
Automatically selected FileSet: FileSet1
+-------+-------+----------+----------+---------------------+--------------------------------+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
+-------+-------+----------+----------+---------------------+--------------------------------+
| 106 | F | 29 | 237,101 | 2017-07-16 10:37:01 | client1-backup-2017-07-16-id95 |
| 107 | I | 3 | 87,230 | 2017-07-16 10:45:13 | client1-backup-2017-07-16-id95 |
+-------+-------+----------+----------+---------------------+--------------------------------+
You have selected the following JobIds: 106,107 # 查找到最近的一次是1个全量(106)加1个增量(107)
Building directory tree for JobId(s) 106,107 ...
28 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: /
$ ls
var/
$ cd var/log/
cwd is: /var/log/
$ ls
anaconda.ifcfg.log
anaconda.log
anaconda.program.log
anaconda.storage.log
anaconda.syslog
anaconda.xlog
anaconda.yum.log
audit/
boot.log
btmp
cron
cron-20170716
dmesg
dmesg.old
dracut.log
lastlog
maillog
maillog-20170716
messages
messages-20170716
mysqld.log
secure
secure-20170716
spooler
spooler-20170716
tallylog
wtmp
$ mark messages
# 标记需要还原的文件
# mark * 标记全部
# unmark messages 不标记的内容,只能unmark已经标记的
1 file marked.
$ done #确认还原
Bootstrap records written to /root/bacula/bin/working/server-dir.restore.1.bsr
Bootstrap records written to /root/bacula/bin/working/server-dir.restore.1.bsr
The Job will require the following (*=>InChanger):
Volume(s) Storage(s) SD Device(s)
===========================================================================
client1-backup-2017-07-16-id95 File1 FileChgr1
Volumes marked with "*" are in the Autochanger.
1 file selected to be restored.
在客户端的/opt目录下查看恢复的内容
[root@client opt]# cd /opt/var/log/
[root@client log]# ls
Messages # 文件已恢复
1.7. delete删除备份记录
*delete
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
In general it is not a good idea to delete either a
Pool or a Volume since they may contain data.
You have the following choices:
1: volume
2: pool
3: jobid
4: snapshot
Choose catalog item to delete (1-4): 1
Defined Pools:
1: Default
2: File
3: Scratch
4: Pool1
Select the Pool (1-4): 4
+---------+-------------+-----------+---------+----------------+----------+--------------+---------+------+-----------+-----------+---------------------+------------+
| MediaId | VolumeName | VolStatus | Enabled | VolBytes | VolFiles | VolRetention | Recycle | Slot | InChanger | MediaType | LastWritten | ExpiresIn |
+---------+-------------+-----------+---------+----------------+----------+--------------+---------+------+-----------+-----------+---------------------+------------+
| 16 | Backup-0016 | Purged | 1 | 21,474,832,957 | 4 | 31,536,000 | 1 | 0 | 0 | File1 | 2017-09-29 13:01:53 | 22,278,875 |
| 17 | Backup-0017 | Purged | 1 | 21,474,818,922 | 4 | 31,536,000 | 1 | 0 | 0 | File1 | 2017-09-29 13:35:54 | 22,280,916 |
| 18 | Backup-0018 | Purged | 1 | 21,474,818,951 | 4 | 31,536,000 | 1 | 0 | 0 | File1 | 2017-09-29 14:09:56 | 22,282,958 |
| 19 | Backup-0019 | Purged | 1 | 21,474,818,846 | 4 | 31,536,000 | 1 | 0 | 0 | File1 | 2017-09-29 14:43:57 | 22,284,999 |
| 20 | Backup-0020 | Purged | 1 | 21,474,809,417 | 4 | 31,536,000 | 1 | 0 | 0 | File1 | 2017-10-01 00:36:35 | 22,406,957 |
…
+---------+-------------+-----------+---------+----------------+----------+--------------+---------+------+-----------+-----------+---------------------+------------+
Enter a Volume name or *MediaId: *16
This command will delete volume Backup-0016
and all Jobs saved on that volume from the Catalog
Are you sure you want to delete Volume "Backup-0016"? (yes/no): yes
Delete 删除的是数据库里备份的记录,备份的真实文件不会删除
也可以指定指定删除的volume、pool、jobs,直接删除(批量删除)
# 批量删除volume
delete volume=Vol-0085 pool=Pool1 yes
delete volume=Vol-0086 pool=Pool1 yes
delete volume=Vol-0087 pool=Pool1 yes
This command will delete volume Backup-0017
and all Jobs saved on that volume from the Catalog
# 批量删除JOB
delete jobid=18 yes
delete jobid=19 yes
1.8. update更新(修改备份状态信息)
*update volume
Using Catalog "MyCatalog"
Parameters to modify:
1: Volume Status
2: Volume Retention Period
3: Volume Use Duration
4: Maximum Volume Jobs
5: Maximum Volume Files
6: Maximum Volume Bytes
7: Recycle Flag
8: Slot
9: InChanger Flag
10: Volume Files
11: Pool
12: Volume from Pool
13: All Volumes from Pool
14: All Volumes from all Pools
15: Enabled
16: RecyclePool
17: Action On Purge
18: Done
Select parameter to modify (1-18): 2 # 修改volume Retention
Defined Pools:
1: Default
2: File
3: Scratch
4: Pool1
Select the Pool (1-4): 4
+---------+------------+-----------+---------+-------------+----------+--------------+---------+------+-----------+-----------+---------------------+-----------+
| MediaId | VolumeName | VolStatus | Enabled | VolBytes | VolFiles | VolRetention | Recycle | Slot | InChanger | MediaType | LastWritten | ExpiresIn |
+---------+------------+-----------+---------+-------------+----------+--------------+---------+------+-----------+-----------+---------------------+-----------+
| 6 | sky-0006 | Full | 1 | 10,434,870 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-29 23:10:01 | 0 |
| 8 | sky-0008 | Full | 1 | 1,032,403 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-29 23:10:01 | 0 |
| 9 | sky-0009 | Full | 1 | 1,032,403 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-29 23:15:02 | 0 |
| 11 | sky-0011 | Full | 1 | 1,032,403 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-29 23:09:57 | 0 |
| 12 | sky-0012 | Full | 1 | 104,815,926 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-29 23:10:00 | 0 |
| 13 | sky-0013 | Full | 1 | 104,812,295 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-29 23:09:56 | 0 |
| 14 | sky-0014 | Full | 1 | 104,845,581 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-30 22:50:24 | 0 |
| 15 | sky-0015 | Full | 1 | 104,832,211 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-30 22:50:28 | 0 |
| 16 | sky-0016 | Full | 1 | 104,849,950 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-30 22:50:32 | 0 |
| 17 | sky-0017 | Purged | 1 | 104,801,017 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-12 05:52:54 | 0 |
| 18 | sky-0018 | Purged | 1 | 104,801,017 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-12 05:52:51 | 0 |
| 19 | sky-0019 | Full | 1 | 104,795,818 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2017-11-30 22:50:41 | 0 |
| 20 | sky-0020 | Full | 1 | 104,795,411 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-14 05:54:40 | 53,691 |
| 21 | sky-0021 | Full | 1 | 104,828,675 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-14 12:45:02 | 78,313 |
| 22 | sky-0022 | Full | 1 | 104,797,721 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-14 07:25:02 | 59,113 |
| 23 | sky-0023 | Purged | 1 | 104,801,017 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-12 05:52:46 | 0 |
| 24 | sky-0024 | Append | 1 | 47,138,302 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-14 14:55:02 | 86,113 |
| 25 | sky-0025 | Purged | 1 | 104,818,041 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-13 05:58:19 | 0 |
| 26 | sky-0026 | Purged | 1 | 104,801,017 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-12 05:52:39 | 0 |
| 27 | sky-0027 | Full | 1 | 104,815,926 | 0 | 3,600 | 1 | 0 | 0 | File1 | 2017-11-29 23:20:05 | 0 |
| 28 | aaa | Purged | 1 | 104,816,609 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-12 05:52:43 | 0 |
| 29 | aaa1 | Purged | 1 | 104,836,570 | 0 | 86,400 | 1 | 0 | 0 | File1 | 2018-01-13 05:53:15 | 0 |
| 30 | sky | Append | 1 | 206 | 0 | 86,400 | 1 | 0 | 0 | File1 | NULL | NULL |
+---------+------------+-----------+---------+-------------+----------+--------------+---------+------+-----------+-----------+---------------------+-----------+
Enter a Volume name or *MediaId: *26 # 选择需要修改的volume
Updating Volume "sky-0026"
Current retention period is: 1 day
Enter Volume Retention period: 3600 # 输入需要修改的时间(单位:s)
New retention period is: 1 hour
Parameters to modify:
1: Volume Status
2: Volume Retention Period
3: Volume Use Duration
4: Maximum Volume Jobs
5: Maximum Volume Files
6: Maximum Volume Bytes
7: Recycle Flag
8: Slot
9: InChanger Flag
10: Volume Files
11: Pool
12: Volume from Pool
13: All Volumes from Pool
14: All Volumes from all Pools
15: Enabled
16: RecyclePool
17: Action On Purge
18: Done
Select parameter to modify (1-18): 18
Selection terminated.
1.9. Purge备份记录
Purge Purge records from catalog
Purge file/job/volume会将记录清除,但对应的磁盘文件不会删除,系统会标记volume为purged,新的备份会自动写入到purged volume中。
无论purge file/job/volume,对应的file/job/volume将无法恢复,所有此操作非常危险,请谨慎使用。
*purge
This command can be DANGEROUS!!!
It purges (deletes) all Files from a Job,
JobId, Client or Volume; or it purges (deletes)
all Jobs from a Client or Volume without regard
to retention periods. Normally you should use the
PRUNE command, which respects retention periods.
You have the following choices:
1: files
2: jobs
3: volume
Choose item to purge (1-3): 2 #清除job记录
The defined Client resources are:
1: server-fd
2: client1-fd
Select Client (File daemon) resource (1-2): 1 # 选择client
Begin purging jobs from Client "server-fd"
6 Jobs for client server-fd purged from MyCatalog catalog.
# 批量pruge volume
purge volume=Vol-0104 pool=Pool1 yes
purge volume=Vol-0105 pool=Pool1 yes
purge volume=Vol-0106 pool=Pool1 yes
purge volume=Vol-0107 pool=Pool1 yes
1.10. Prune备份记录
Prune是个比较安全的操作,当volume没有达到VolRetention时间即使prune操作了也不会有影响。
# 批量prune
prune volume=Vol-0001 pool=Pool1 yes
prune volume=Vol-0002 pool=Pool1 yes
prune volume=Vol-0003 pool=Pool1 yes
prune volume=Vol-0004 pool=Pool1 yes