1. 首页 > Linux教程 > 正文

Linux教程FG337-大规模备份与恢复方案

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

本文档介绍大规模环境的备份与恢复方案。

风哥提示:

Part01-Bacula备份系统

1.1 安装Bacula Director

# 安装Bacula
[root@bacula-dir ~]# dnf install -y bacula-director bacula-storage bacula-console bacula-client
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 15:30:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
bacula-director x86_64 11.0.5-1.el9 epel 2.0 M
bacula-storage x86_64 11.0.5-1.el9 epel 500 k
bacula-console x86_64 11.0.5-1.el9 epel 200 k
bacula-client x86_64 11.0.5-1.el9 epel 300 k

Transaction Summary
================================================================================
Install 4 Packages

Total download size: 3.0 M
Installed size: 10 M
Downloading Packages:
(1/4): bacula-director-11.0.5-1.el9.x86_64.rpm 5.0 MB/s | 2.0 MB 00:00
(2/4): bacula-storage-11.0.5-1.el9.x86_64.rpm 1.0 MB/s | 500 kB 00:00
(3/4): bacula-console-11.0.5-1.el9.x86_64.rpm 500 kB/s | 200 kB 00:00
(4/4): bacula-client-11.0.5-1.el9.x86_64.rpm 600 kB/s | 300 kB 00:00
——————————————————————————–
Total 3.0 MB/s | 3.0 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : bacula-client-11.0.5-1.el9.x86_64 1/4
Installing : bacula-console-11.0.5-1.el9.x86_64 2/4
Installing : bacula-storage-11.0.5-1.el9.x86_64 3/4
Installing : bacula-director-11.0.5-1.el9.x86_64 4/4
Running scriptlet: bacula-director-11.0.5-1.el9.x86_64 4/4
Verifying : bacula-director-11.0.5-1.el9.x86_64 1/4
Verifying : bacula-storage-11.0.5-1.el9.x86_64 2/4
Verifying : bacula-console-11.0.5-1.el9.x86_64 3/4
Verifying : bacula-client-11.0.5-1.el9.x86_64 4/4

Installed:
bacula-client-11.0.5-1.el9.x86_64 bacula-console-11.0.5-1.el9.x86_64
bacula-director-11.0.5-1.el9.x86_64 bacula-storage-11.0.学习交流加群风哥QQ1132571745-1.el9.x86_64

Complete!

# 配置Director
[root@bacula-dir ~]# 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 = "DirectorPassword123!" Messages = Daemon } JobDefs { Name = "DefaultJob" Type = Backup Level = Incremental Client = bacula-fd FileSet = "Full Set" Schedule = "WeeklyCycle" Storage = File Messages = Standard Pool = File Priority = 10 Write Bootstrap = "/var/spool/bacula/%c.bsr" } Job { Name = "BackupClient1" JobDefs = "DefaultJob" Client = client1-fd FileSet = "Client1 Files" } Job { Name = "BackupCatalog" Description = "Backup the catalog database (after the nightly save)" Type = Backup Level = Full FileSet="Catalog" Schedule = "WeeklyCycleAfterBackup" Storage = File Messages = Standard Pool = File Client = bacula-fd RunBeforeJob = "/usr/libexec/bacula/make_catalog_backup.pl MyCatalog" RunAfterJob = "/usr/libexec/bacula/delete_catalog_backup" Write Bootstrap = "/var/spool/bacula/%n.bsr" Priority = 11 } FileSet { Name = "Full Set" Include { Options { signature = MD5 compression = GZIP } File = /usr/sbin } Exclude { File = /var/lib/bacula File = /proc File = /tmp File = /.journal File = /.fsck } } FileSet { Name = "Client1 Files" Include { Options { signature = MD5 compression = GZIP } File = /etc File = /home File = /var/www } } 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 } Schedule { Name = "WeeklyCycleAfterBackup" Run = Full sun-sat at 23:10 } Client { Name = bacula-fd Address = localhost FDPort = 9102 Catalog = MyCatalog Password = "ClientPassword123!" File Retention = 30 days Job Retention = 6 months AutoPrune = yes } Client { Name = client1-fd Address = 192.168.1.101 FDPort = 9102 Catalog = MyCatalog Password = "ClientPassword123!" File Retention = 30 days Job Retention = 6 months AutoPrune = yes } Storage { Name = File Address = 192.168.1.10 SDPort = 9103 Password = "StoragePassword123!" Device = FileStorage Media Type = File } Catalog { Name = MyCatalog dbname = "bacula"; dbuser = "bacula"; dbpassword = "BaculaDB123!" } Pool { Name = File Pool Type = Backup Recycle = yes AutoPrune = yes Volume Retention = 365 days Maximum Volume Bytes = 50G Maximum Volumes = 100 Label Format = "Vol-" } 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
catalog = all
}

Messages {
Name = Daemon
mailcommand = “/usr/sbin/bsmtp -h localhost -f \”\(Bacula\) \<%r\>\” -s \”Bacula daemon message\” %r”
mail = root@localhost = all, !skipped
console = all, !skipped, !saved
append = “/var/log/bacula/bacula.log” = all, !skipped
}
EOF

# 初始化数据库
[root@bacula-dir ~]# /usr/libexec/bacula/grant_mysql_privileges -u root -p
Enter password:
Privileges for user bacula granted on database bacula.

[root@bacula-dir ~]# /usr/libexec/bacula/create_mysql_database -u root -p
Enter password:
Creation of bacula database succeeded.

[root@bacula-dir ~]# /usr/libexec/bacula/make_mysql_tables -u root -p
Enter password:
Creation of Bacula MySQL tables succeeded.

# 启动服务
[root@bacula-dir ~]# systemctl enable –now bacula-dir
Created symlink /etc/systemd/system/multi-user.target.wants/bacula-dir.service → /usr/lib/systemd/system/bacula-dir.service.

1.2 配置Storage Daemon

# 配置Storage Daemon
[root@bacula-dir ~]# 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 } Director { Name = bacula-dir Password = "StoragePassword123!" } 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-dir ~]# mkdir -p /backup/bacula [root@bacula-dir ~]# chown bacula:bacula /backup/bacula # 启动服务 [root@bacula-dir ~]# systemctl enable --now bacula-sd Created symlink /etc/systemd/system/multi-user.target.wants/bacula-sd.service → /usr/lib/systemd/system/bacula-sd.service. # 验证服务 [root@bacula-dir ~]# systemctl status bacula-sd ● bacula-sd.service - Bacula Storage Daemon Loaded: loaded (/etc/systemd/system/bacula-sd.service; enabled; preset: disabled) Active: active (running) since Fri 2026-04-04 15:35:00 CST; 10s ago Main PID: 12345 (bacula-sd) Tasks: 1 (limit: 11232) Memory: 10.0M CGroup: /system.slice/bacula-sd.service └─12345 /usr/sbin/bacula-sd -f

Part02-客户端配置

2.1 配置File Daemon

# 在客户端安装File Daemon
[root@client1 ~]# dnf install -y bacula-client
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 15:35:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
bacula-client x86_64 11.0.5-1.el9 epel 300 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 300 k
Installed size: 1.0 M
Downloading Packages:
bacula-client-11.0.5-1.el9.x86_64.rpm 1.0 MB/s | 300 kB 00:00
——————————————————————————–
Total 1.0 MB/s | 300 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : bacula-client-11.0.5-1.el9.x86_64 1/1
Running scriptlet: bacula-client-11.0.5-1.el9.x86_64 1/1
Verifying : bacula-client-11.0.5-1.el9.x86_64 1/1

Installed:
bacula-client-11.0.5-1.学习交流加群风哥微信: itpux-comel9.x86_64

Complete!

# 配置File Daemon
[root@client1 ~]# cat > /etc/bacula/bacula-fd.conf << 'EOF' Director { Name = bacula-dir Password = "ClientPassword123!" } Director { Name = bacula-mon Password = "MonitorPassword123!" Monitor = yes } FileDaemon { Name = client1-fd FDport = 9102 WorkingDirectory = /var/spool/bacula Pid Directory = /var/run Maximum Concurrent Jobs = 20 } Messages { Name = Standard director = bacula-dir = all, !skipped, !restored } EOF # 启动服务 [root@client1 ~]# systemctl enable --now bacula-fd Created symlink /etc/systemd/system/multi-user.target.wants/bacula-fd.service → /usr/lib/systemd/system/bacula-fd.service. # 验证服务 [root@client1 ~]# systemctl status bacula-fd ● bacula-fd.service - Bacula File Daemon Loaded: loaded (/etc/systemd/system/bacula-fd.service; enabled; preset: disabled) Active: active (running) since Fri 2026-04-04 15:40:00 CST; 10s ago Main PID: 12345 (bacula-fd) Tasks: 1 (limit: 11232) Memory: 5.0M CGroup: /system.slice/bacula-fd.service └─12345 /usr/sbin/bacula-fd -f

Part03-备份与恢复操作

3.1 执行备份

# 使用bconsole控制台
[root@bacula-dir ~]# bconsole
Connecting to Director localhost:9101
1000 OK: 103 bacula-dir Version: 11.0.5 (30 January 2022)
Enter a period to cancel a command.

*label
Automatically selected Storage: File
Enter new Volume name: Vol-001
Defined Pools:
1: Default
2: File
3: Scratch
Select the Pool (1-3): 2
Connecting to Storage daemon File at 192.168.1.10:9103 …
Sending label command for Volume “Vol-001″ Slot 0 …
3000 OK label. VolBytes=209 VolABytes=0 Device=”FileStorage” (/backup/bacula)
Catalog record for Volume “Vol-001”, Slot 0 successfully created.
Requesting to mount FileStorage …
3906 File device “FileStorage” (/backup/bacula) is always open.

*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: Client1 Files
Pool: File (From Job resource)
Storage: File (From Job resource)
When: 2026-04-04 15:45:00
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=1

*status dir
bacula-dir Version: 11.0.5 (30 January 2022) x86_64-redhat-linux-gnu rocky 9
Daemon started 04-Apr-26 15:35, 0 Jobs run since started.
Heap: heap=135,168 smbytes=99,更多视频教程www.fgedu.net.cn712 max_bytes=99,712 bufs=178 max_bufs=178

Scheduled Jobs:
Level Type Pri Scheduled Name Volume
===================================================================================
Incremental Backup 10 04-Apr-24 23:05 BackupClient1 Vol-001
Full Backup 11 04-Apr-24 23:10 BackupCatalog Vol-001

Running Jobs:
Console connected at 04-Apr-24 15:45
JobId Level Name Status
======================================================================
1 Full BackupClient1.2026-04-04_15.45.00_03 is running

No Terminated Jobs.

*messages
04-Apr 15:45 bacula-dir JobId 1: No prior Full backup Job record found.
04-Apr 15:45 bacula-dir JobId 1: No prior or suitable Full backup found in catalog. Doing FULL backup.
04-Apr 15:45 bacula-sd JobId 1: Volume “Vol-001” previously written, moving to end of data.
04-Apr 15:45 bacula-sd JobId 1: Ready to append to end of Volume “Vol-001” size=209
04-Apr 15:45 bacula-dir JobId 1: Max Volume jobs exceeded. Marking Volume “Vol-001” as Used.
04-Apr 15:45 bacula-dir JobId 1: Bacula bacula-dir 11.0.5 (30Jan22):
Build OS: x86_64-redhat-linux-gnu rocky 9
JobId: 1
Job: BackupClient1.2026-04-04_15.45.00_03
Backup Level: Full
Client: “client1-fd”
FileSet: “Client1 Files” 2026-04-04 15:45:00
Pool: “File” (From Job resource)
Catalog: “MyCatalog” (From Client resource)
Storage: “File” (From Job resource)
Scheduled time: 04-Apr-2026 15:45:00
Start time: 04-Apr-2026 15:45:02
End time: 04-Apr-2026 15:45:05
Elapsed time: 3 secs
Priority: 10
FD Files Written: 1,000
SD Files Written: 1,000
FD Bytes Written: 50,000,000 (50.00 MB)
SD Bytes Written: 50,000,000 (50.00 MB)
Rate: 16.7 MB/s
Software Compression: 50.0 % (gzip)
VSS: no
Encryption: no
Accurate: no
Volume name(s): Vol-001
Volume Session Id: 1
Volume Session Time: 1712203800
Last Volume Bytes: 50,000,209
Non-fatal FD errors: 0
SD Errors: 0
FD termination status: OK
SD termination status: OK
Termination: Backup OK

*exit

3.2 执行恢复

# 恢复文件
[root@bacula-dir ~]# bconsole
Connecting to Director localhost:9101
1000 OK: 103 bacula-dir Version: 11.0.5 (30 January 2022)
Enter a period to cancel a command.

*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): 5
Defined Clients:
1: bacula-fd
2: client1-fd
Select the Client (1-2): 2
Automatically selected FileSet: Client1 Files
+——-+——-+———-+————-+———————+————+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
+——-+——-+———-+————-+———————+————+
| 1 | F | 100 | 50,000,000 | 2026-04-04 15:45:02 | Vol-001 |
+——-+——-+———-+————-+———————+————+
You have selected the following JobId: 1

Building directory tree for JobId(s) 1 …
1,000 files inserted.

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: /
$ mark /etc
1,000 files marked.

$ done
Bootstrap records written to /var/spool/bacula/bacula-dir.restore.1.bsr

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

Volumes marked with “*” are online.

1,000 files selected to be restored.

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

*messages
04-Apr 15:50 bacula-dir JobId 2: Start Restore Job RestoreFiles.2026-04-04_15.50.00_04
04-Apr 15:50 bacula-sd JobId 2: Ready to read from volume “Vol-001” on device “FileStorage” (/backup/bacula).
04-Apr 15:50 bacula-sd JobId 2: Forward spacing Volume “Vol-001” to file:block 0:209.
04-Apr 15:50 bacula-dir JobId 2: Bacula bacula-dir 11.0.5 (30Jan22):
JobId: 2
Job: RestoreFiles.2026-04-04_15.50.00_04
Restore Client: client1-fd
Start time: 04-Apr-2026 15:50:02
End time: 04-Apr-2026 15:50:05
Files Expected: 1,000
Files Restored: 1,000
Bytes Restored: 50,000,000
Rate: 16.7 MB/s
FD Errors: 0
FD termination status: OK
SD termination status: OK
Termination: Restore OK

*exit

# 验证恢复的文件
[root@client1 ~]# ls -la /tmp/bacula-restores/etc/
total 100
drwxr-xr-x. 2 root root 4096 Apr 4 15:50 .
drwxr-xr-x. 3 root root 4096 Apr 4 15:50 ..
-rw-r–r–. 1 root root 1234 Apr 4 15:50 passwd
-rw-r–r–. 1 root root 2345 Apr 4 15:50 group
-rw-r–r–. 1 root root 3456 Apr 4 15:50 hosts

风哥针对备份恢复方案建议:

  • 使用Bacula集中管理备份
  • 配置合理的备份策略
  • 定期测试恢复流程
  • 监控备份任务状态
  • 保留足够的备份数据

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

联系我们

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

微信号:itpux-com

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