搬瓦工 VPS 搭建 Bacula 企业级备份系统教程

Bacula 是一款成熟的企业级开源备份解决方案,采用客户端-服务器架构,支持跨平台(Linux、Windows、macOS)的集中化备份管理。Bacula 由 Director(调度中心)、Storage Daemon(存储守护)和 File Daemon(客户端代理)三个核心组件组成,支持全量、增量和差异备份策略。本教程将介绍如何在搬瓦工 VPS 上部署 Bacula 备份系统。部署前请确保已安装好 Docker 和 Docker Compose

一、Bacula 架构组件

  • Director (DIR):备份系统的大脑,负责调度备份作业、管理目录数据库和协调其他组件。
  • Storage Daemon (SD):负责管理备份存储介质,接收和写入备份数据。
  • File Daemon (FD):安装在每台需要备份的客户端上,负责读取本地文件并发送给 Storage Daemon。
  • Catalog (数据库):使用 PostgreSQL 或 MySQL 存储备份作业记录和文件索引。
  • Console (bconsole):命令行管理工具,用于监控和管理备份系统。

二、安装 Bacula

# Ubuntu/Debian 安装
apt update
apt install bacula-server bacula-client bacula-console -y

# 安装过程中会自动配置 PostgreSQL 数据库
# 按提示设置数据库密码

三、配置 Director

# 编辑 Director 配置
cat > /etc/bacula/bacula-dir.conf <<'EOF'
Director {
  Name = vps-dir
  DIRport = 9101
  QueryFile = "/etc/bacula/scripts/query.sql"
  WorkingDirectory = "/var/lib/bacula"
  PidDirectory = "/run/bacula"
  Maximum Concurrent Jobs = 5
  Password = "director_console_pass_2026"
  Messages = Daemon
}

# 备份作业定义
Job {
  Name = "BackupWebsite"
  Type = Backup
  Level = Incremental
  Client = vps-fd
  FileSet = "WebsiteFiles"
  Schedule = "WeeklyCycle"
  Storage = File1
  Pool = Default
  Messages = Standard
  Priority = 10
  Write Bootstrap = "/var/lib/bacula/%c.bsr"
}

# 恢复作业
Job {
  Name = "RestoreFiles"
  Type = Restore
  Client = vps-fd
  Storage = File1
  FileSet = "WebsiteFiles"
  Pool = Default
  Messages = Standard
  Where = /tmp/bacula-restores
}

# 文件集定义
FileSet {
  Name = "WebsiteFiles"
  Include {
    Options {
      signature = MD5
      compression = GZIP
    }
    File = /opt/app
    File = /var/www
    File = /etc/nginx
  }
  Exclude {
    File = /opt/app/node_modules
    File = /opt/app/.git
    File = /var/www/cache
  }
}

# 调度计划
Schedule {
  Name = "WeeklyCycle"
  Run = Full 1st sun at 01:05
  Run = Differential 2nd-5th sun at 01:05
  Run = Incremental mon-sat at 01:05
}

# 存储配置
Storage {
  Name = File1
  Address = 127.0.0.1
  SDPort = 9103
  Password = "storage_pass_2026"
  Device = FileChgr1
  Media Type = File
  Maximum Concurrent Jobs = 5
}

# 客户端定义
Client {
  Name = vps-fd
  Address = 127.0.0.1
  FDPort = 9102
  Password = "client_pass_2026"
  File Retention = 60 days
  Job Retention = 6 months
  AutoPrune = yes
}

# 存储池
Pool {
  Name = Default
  Pool Type = Backup
  Recycle = yes
  AutoPrune = yes
  Volume Retention = 365 days
  Maximum Volume Bytes = 50G
  Maximum Volumes = 100
  Label Format = "Vol-"
}

Catalog {
  Name = MyCatalog
  dbname = "bacula"
  dbuser = "bacula"
  dbpassword = "bacula_db_pass_2026"
}

Messages {
  Name = Standard
  mailcommand = "/usr/sbin/bsmtp -h localhost -f bacula@example.com -s \"Bacula: %t %e of %c %l\" %r"
  mail = admin@example.com = all, !skipped
  console = all, !skipped, !saved
  append = "/var/log/bacula/bacula.log" = all, !skipped
  catalog = all
}

Messages {
  Name = Daemon
  console = all, !skipped, !saved
  append = "/var/log/bacula/bacula.log" = all, !skipped
}
EOF

四、配置 Storage Daemon

cat > /etc/bacula/bacula-sd.conf <<'EOF'
Storage {
  Name = vps-sd
  SDPort = 9103
  WorkingDirectory = "/var/lib/bacula"
  PidDirectory = "/run/bacula"
  Maximum Concurrent Jobs = 5
}

Director {
  Name = vps-dir
  Password = "storage_pass_2026"
}

Device {
  Name = FileChgr1-Dev1
  Media Type = File
  Archive Device = /backup/bacula
  LabelMedia = yes
  Random Access = yes
  AutomaticMount = yes
  RemovableMedia = no
  AlwaysOpen = no
  Maximum Concurrent Jobs = 5
}

Autochanger {
  Name = FileChgr1
  Device = FileChgr1-Dev1
  Changer Command = ""
  Changer Device = /dev/null
}

Messages {
  Name = Standard
  director = vps-dir = all
}
EOF

mkdir -p /backup/bacula

五、配置 File Daemon

cat > /etc/bacula/bacula-fd.conf <<'EOF'
FileDaemon {
  Name = vps-fd
  FDport = 9102
  WorkingDirectory = /var/lib/bacula
  PidDirectory = /run/bacula
  Maximum Concurrent Jobs = 5
  FDAddress = 127.0.0.1
}

Director {
  Name = vps-dir
  Password = "client_pass_2026"
}

Messages {
  Name = Standard
  director = vps-dir = all, !skipped, !restored
}
EOF

六、启动服务

systemctl restart bacula-director
systemctl restart bacula-sd
systemctl restart bacula-fd
systemctl enable bacula-director bacula-sd bacula-fd

# 检查服务状态
systemctl status bacula-director bacula-sd bacula-fd

七、使用 bconsole 管理

# 进入控制台
bconsole

# 常用命令
*status dir         # 查看 Director 状态
*status client      # 查看客户端状态
*status storage     # 查看存储状态
*list jobs          # 列出所有作业
*run                # 手动运行备份
*restore            # 恢复数据
*label              # 标记存储卷
*messages           # 查看消息

八、Web 管理界面(Baculum)

# 使用 Docker 部署 Baculum Web 管理界面
docker run -d --name baculum \
  -p 127.0.0.1:9095:9095 \
  -v /etc/bacula:/etc/bacula:ro \
  bacularis/bacularis-app:latest

通过 SSH 隧道访问 9095 端口,即可使用图形界面管理备份作业、浏览存储池和执行恢复操作。

九、常见问题

Director 无法连接 Storage Daemon

# 检查端口和密码配置
ss -tlnp | grep 9103
# 确保 Director 中的 Storage Password 与 SD 配置中的 Director Password 一致

备份卷空间不足

调整存储池的 Volume Retention 和 Maximum Volume Bytes 参数,或配置 AutoPrune 自动回收过期卷。

总结

Bacula 是功能最完善的开源企业备份方案,适合需要管理多台服务器备份的场景。如果只需要单机备份,ResticBorgBackup 更加轻量易用。选购搬瓦工 VPS 请参考 全部方案,购买时使用优惠码 NODESEEK2026 可享受 6.77% 的折扣,购买链接:bwh81.net

关于本站

搬瓦工VPS中文网(bwgvps.com)是非官方中文信息站,整理搬瓦工的方案、优惠和教程。我们不销售主机,不提供技术服务。

新手必读
搬瓦工优惠码

NODESEEK2026(优惠 6.77%)

购买时填入即可抵扣。