1. 首页 > Linux教程 > 正文

Linux教程FG389-备份恢复平台实战

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

本文档介绍备份恢复平台的部署和应用。

风哥提示:

Part01-Bacula部署

1.1 安装Bacula

# 安装Bacula
[root@bacula ~]# dnf install -y bacula-director bacula-storage bacula-console bacula-client

# 配置数据库
[root@bacula ~]# alternatives –set libbaccats.so /usr/lib64/libbaccats-mysql.so
[root@bacula ~]# mysql -u root -p
mysql> CREATE DATABASE bacula;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON bacula.* TO ‘bacula’@’localhost’ IDENTIFIED BY ‘Bacula@123456’;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

# 初始化数据库
[root@bacula ~]# /usr/libexec/bacula/make_mysql_tables -u bacula -pBacula@123456
Creation of Bacula MySQL tables succeeded.

# 配置Bacula Director
[root@bacula ~]# cat > /etc/bacula/bacula-dir.conf << 'EOF' Director { Name = bacula-dir DIRport = 9101 QueryFile = "/etc/bacula/query.sql" WorkingDirectory = "/var/spool/bacula" PidDirectory = "/var/run" Maximum Concurrent Jobs = 20 Password = "Director@123456" Messages = Daemon } JobDefs { Name = "DefaultJob" Type = Backup Level = Incremental Client = bacula-fd FileSet = "Full Set" Schedule = "WeeklyCycle" Storage = File Messages = Standard Pool = Default Priority = 10 Write Bootstrap = "/var/spool/bacula/%c.bsr" } Job { Name = "BackupClient1" JobDefs = "DefaultJob" Client = client1-fd } Job { Name = "BackupCatalog" JobDefs = "DefaultJob" Level = Full FileSet="Catalog" Schedule = "WeeklyCycleAfterBackup" RunBeforeJob = "/usr/libexec/bacula/make_catalog_backup.pl MyCatalog" RunAfterJob = "/usr/libexec/bacula/delete_catalog_backup" Write Bootstrap = "|/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\” -s \”Bootstrap for Job %j\” root@localhost”
Priority = 11
}

FileSet {
Name = “Full Set”
Include {
Options {
signature = MD5
compression = GZIP
}
File = /etc
File = /var/www
File = /home
}
Exclude {
File = /var/spool/bacula
File = /tmp
File = /proc
File = /sys
}
}

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
}

Storage {
Name = File
Address = 192.168.1.100
SDPort = 9103
Password = “Storage@123456”
Device = FileStorage
Media Type = File
}

Pool {
Name = Default
Pool Type = Backup
Recycle = yes
AutoPrune = yes
Volume Retention = 365 days
Maximum Volume Bytes = 50G
Maximum Volumes = 100
Label Format = “Vol-”
}

Client {
Name = client1-fd
Address = 192.168.1.20
FDPort = 9102
Catalog = MyCatalog
Password = “Client@123456”
File Retention = 60 days
Job Retention = 6 months
AutoPrune = yes
}

Catalog {
Name = MyCatalog
dbname = “bacula”; dbuser = “bacula”; dbpassword = “Bacula@123456”
}

Messages {
Name = Standard
mailcommand = “/usr/sbin/bsmtp -h localhost -f \”\(Bacula\) \<%r\>\” -s \”Bacula: %t %e of %c %l\” %r”
operatorcommand = “/usr/sbin/bsmtp -h localhost -f \”\(Bacula\) \<%r\>\” -s \”Bacula: Intervention needed for %j\” %r”
mail = root@localhost = all, !skipped
operator = root@localhost = mount
console = all, !skipped, !saved
append = “/var/log/bacula/bacula.log” = all, !skipped
}
EOF

# 配置Storage Daemon
[root@bacula ~]# cat > /etc/bacula/bacula-sd.conf << 'EOF' Storage { Name = bacula-sd SDPort = 9103 WorkingDirectory = "/var/spool/bacula" Pid Directory = "/var/run" Maximum Concurrent Jobs = 20 } Device { Name = FileStorage Media Type = File Archive Device = /backup/bacula LabelMedia = yes; Random Access = Yes; AutomaticMount = yes; RemovableMedia = no; AlwaysOpen = no; } Messages { Name = Standard director = bacula-dir = all } EOF # 创建备份目录 [root@bacula ~]# mkdir -p /backup/bacula [root@bacula ~]# chown bacula:bacula /backup/bacula # 启动服务 [root@bacula ~]# systemctl enable --now bacula-dir [root@bacula ~]# systemctl enable --now bacula-sd

Part02-备份恢复操作

2.1 执行备份

# 使用bconsole管理备份
[root@bacula ~]# bconsole
Connecting to Director localhost:9101
1000 OK: 103 bacula-dir Version: 11.0.5 (28 January 2022)
Enter a period to cancel a command.

*label
Automatically selected Catalog: MyCatalog
Using Catalog “MyCatalog”
The defined Storage resources are:
1: File
Select Storage resource (1-1): 1
Enter new Volume name: Vol-0001
Defined Pools:
1: Default
2: Scratch
Select the Pool (1-2): 更多学习教程公众号风哥教程itpux_com1
Connecting to Storage daemon File at 192.168.1.100:9103 …
Sending label command for Volume “Vol-0001″ Slot 0 …
3000 OK label. Volume=Vol-0001 Device=”FileStorage” (/backup/bacula)
Catalog record for Volume “Vol-0001”, Slot 0 successfully created.
Requesting to mount FileStorage …
3906 File device “FileStorage” (/backup/bacula) is always mounted.

*run
A job name must be specified.
The defined Job resources are:
1: BackupClient1
2: BackupCatalog
Select Job resource (1-2): 1
Run Backup job
JobName: BackupClient1
Level: Incremental
Client: client1-fd
FileSet: Full Set
Pool: Default (From Job resource)
Storage: File (From Job resource)
When: 2026-04-04 00:10:00
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=1

*status dir
bacula-dir Version: 11.0.5 (28 January 2022) x86_64-redhat-linux-gnu redhat
Daemon started 04-Apr-26 00:00:00, 0 Jobs run since started.
Heap: heap=135,168 smbytes=101,168 max_bytes=101,168 bufs=86 max_bufs=86

Scheduled Jobs:
Level Type Pri Scheduled Name Volume
===================================================================================
Incremental Backup 10 04-Apr-24 23:05 BackupClient1 Vol-0001
Full Backup 11 05-Apr-24 23:10 BackupCatalog (not required)

Running Jobs:
Console connected at 04-Apr-24 00:05:00
JobId Level Name Status
======================================================================
1 Full BackupClient1.2026-04-04_00.05.00_03 is running

*messages
04-Apr 00:05 bacula-dir JobId 1: No prior Full backup Job record found.
04-Apr 00:05 bacula-dir JobId 1: No prior or suitable Full backup found in catalog. Doing FULL backup.
04-Apr 00:05 bacula-sd JobId 1: Vol-0001 mounted on device “FileStorage” (/backup/bacula).
04-Apr 00:05 bacula-dir JobIdfrom PG视频:www.itpux.com 1: Max Volume bytes exceeded. Marking Volume “Vol-0001” as Used.
04-Apr 00:10 bacula-dir JobId 1: Bacula bacula-dir 11.0.5 (28Jan22): 04-Apr-2026 00:10:00
Build OS: x86_64-redhat-linux-gnu redhat
JobId: 1
Job: BackupClient1.2026-04-04_00.05.00_03
Backup Level: Full (upgraded from Incremental)
Client: “client1-fd” 192.168.1.20
FileSet: “Full Set” 2026-04-04 00:05:00
Pool: “Default” (From Job resource)
Storage: “File” (From Job resource)
Scheduled time: 04-Apr-2026 00:05:00
Start time: 04-Apr-2026 00:05:01
End time: 04-Apr-2026 00:10:00
Elapsed time: 4 mins 59 secs
Priority: 10
FD Files Written: 10,000
SD Files Written: 10,000
FD Bytes Written: 1,000,000,000 (1 GB)
SD Bytes Written: 1,010,000,000 (1.01 GB)
Rate: 3.3 MB/s
Software Compression: 50.0 % (gzip)
VSS: no
Encryption: no
Accurate: no
Volume name(s): Vol-0001
Volume Session Id: 1
Volume Session Time: 1234567890
Last Volume Bytes: 1,010,000,000 (1.01 GB)
Non-fatal FD errors: 0
SD Errors: 0
FD termination status: OK
SD termination status: OK
Termination: Backup OK

2.2 恢复数据

# 恢复数据
*restore
First select a Client to restore. The defined Clients are:
1: client1-fd
Select the Client (1-1): 1
Automatically selected FileSet: Full Set
+——-+——-+———-+—————–+———————+————————-+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
+——-+——-+———-+—————–+———————+————————-+
| 1 | F | 10000 | 1,000,000,000 | 2026-04-04 00:05:01 | Vol-0001 |
+——-+——-+———-+—————–+———————+————————-+

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 for a specified JobId
8: Enter a list of files to restore using a specified Job
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: Cancel
Select item: (1-11): 5
Defined Clients:
1: client1-fd
Select the Client (1-1): 1
The defined FileSet resources are:
1: Full Set
Select FileSet resource (1-1): 1
+——-+——-+———-+—————–+———————+————————-+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
+——-+——-+———-+—————–+———————+————————-+
| 1 | F | 10000 | 1,000,000,000 | 2026-04-04 00:05:01 | Vol-0001 |
+——-+——-+———-+—————–+———————+————————-+

Building directory tree for JobId 1 …
1 files inserted.

You are now entering file selection mode where you add (mark) and
remove (unmark) files to学习交流加群风哥QQ113257174 be restored. No files are initially added.

Enter “done” to leave this mode.

cwd is: /
$ mark /etc
1 files marked.
$ done
Bootstrap records written to /var/spool/bacula/client1-fd.restore.1.bsr

The job will require the following
Volume(s) Storage(s) SD Device(s)
===========================================================================
Vol-0001 File FileStorage

1 file selected to be restored.

Run Restore job
JobName: RestoreFiles
Bootstrap: /var/spool/bacula/client1-fd.restore.1.bsr
Where: /tmp/bacula-restores
Replace: Always
FileSet: Full Set
Backup Client: client1-fd
Restore Client: client1-fd
Format: Native
Storage: File
Catalog: MyCatalog
When: 2026-04-04 00:15:00
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=2

*messages
04-Apr 00:15 bacula-dir JobId 2: Start Restore Job RestoreFiles.2026-04-04_00.15.00_04
04-Apr 00:15 bacula-sd JobId 2: Vol-0001 mounted on device “FileStorage” (/backup/bacula).
04-Apr 00:20 bacula-dir JobId 2: Bacula bacula-dir 11.0.5 (28Jan22): 04-Apr-2026 00:20:00
Build OS: x86_64-redhat-linux-gnu redhat
JobId: 2
Job: RestoreFiles.2026-04-04_00.15.00_04
Restore Client: client1-fd
Start time: 04-Apr-2026 00:15:01
End time: 04-Apr-2026 00:20:00
Elapsed time: 4 mins 59 secs
Files Expected: 1
Files Restored: 1
Bytes Restored: 1,000,000
Rate: 3.3 KB/s
FD Errors: 0
FD termination status: OK
SD termination status: OK
Termination: Restore OK

风哥针对备份恢复建议:

  • 制定备份策略和计划
  • 定期测试恢复流程
  • 异地备份重要数据
  • 监控备份任务状态
  • 保留足够的备份历史

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息