Lessons

Backup with Bacula and rsnapshot

Level: Advanced Module: Monitoring & High Availability 9 min read Lesson 64 of 66

Overview

  • What you’ll learn: The theory behind backup strategies (full, incremental, differential), Bacula’s multi-component architecture (Director, Storage Daemon, File Daemon), how to define backup jobs in bacula-dir.conf, how to configure rsnapshot for hourly/daily/weekly snapshot rotation, and how to perform reliable restores.
  • Prerequisites: System Monitoring Fundamentals (Lesson 61), Log Management (Lesson 63), familiarity with cron scheduling
  • Estimated reading time: 20 minutes

Introduction

Data loss is one of the most devastating events in any computing environment. Whether caused by hardware failure, human error, ransomware, or natural disaster, the loss of critical data can halt business operations and in some cases destroy organizations entirely. Backup is the insurance policy against data loss, and like all insurance, it must be planned, tested, and maintained to be effective.

A robust backup strategy goes far beyond simply copying files. It involves understanding recovery point objectives (RPO) — how much data you can afford to lose — and recovery time objectives (RTO) — how quickly you must restore service. These business requirements drive the choice of backup type, frequency, retention policy, and storage medium.

In this lesson, we will explore fundamental backup concepts, then implement two complementary tools on Ubuntu Server: Bacula, an enterprise-grade network backup suite with a client-server architecture, and rsnapshot, a lightweight filesystem snapshot utility built on rsync and hard links. Together, they provide a defense-in-depth approach to data protection.

Backup Strategy Fundamentals

Before choosing tools, you must understand the three primary backup types and their trade-offs:

  • Full backup: Copies every file in the backup set. It provides the simplest restore (single backup needed) but consumes the most storage and time. Typically performed weekly or monthly.
  • Incremental backup: Copies only files that changed since the last backup of any type. It is fast and storage-efficient, but restoration requires the last full backup plus every subsequent incremental in sequence.
  • Differential backup: Copies all files changed since the last full backup. It strikes a balance — larger than incrementals but simpler to restore (only the full plus the latest differential).

The classic enterprise pattern is the Grandfather-Father-Son (GFS) rotation scheme: daily incrementals (sons), weekly differentials or fulls (fathers), and monthly fulls retained long-term (grandfathers). This balances storage cost with restore speed and data retention compliance.

The 3-2-1 rule is a widely accepted best practice: maintain at least 3 copies of your data, on 2 different storage media, with 1 copy stored off-site. This protects against localized failures such as fire, theft, or site-wide outages.

Bacula Architecture

Bacula is a network backup solution composed of several cooperating daemons. Understanding this architecture is critical before writing configuration.

  • Bacula Director (bacula-dir): The central control daemon. It schedules and supervises all backup, restore, and verify jobs. Configuration lives in /etc/bacula/bacula-dir.conf.
  • Bacula Storage Daemon (bacula-sd): Manages the physical storage media (disk volumes, tape drives). It reads and writes backup data on behalf of the Director. Configuration: /etc/bacula/bacula-sd.conf.
  • Bacula File Daemon (bacula-fd): The client agent installed on each machine to be backed up. It reads files from the local filesystem and sends them to the Storage Daemon. Configuration: /etc/bacula/bacula-fd.conf.
  • Bacula Catalog: A SQL database (MySQL/PostgreSQL) that stores metadata about all backup jobs, volumes, and file locations. It enables fast file-level restore lookups without scanning media.
  • Bacula Console (bconsole): A command-line interface for interacting with the Director — starting jobs, checking status, and performing restores.
# Install Bacula components on Ubuntu
$ sudo apt update
$ sudo apt install -y bacula-director bacula-storage bacula-client 
    bacula-console bacula-common-mysql

# During installation, configure the MySQL/MariaDB catalog database
# Bacula will prompt for database credentials

# Verify all daemons are running
$ sudo systemctl status bacula-director
$ sudo systemctl status bacula-sd
$ sudo systemctl status bacula-fd

Configuring Bacula Director

The Director configuration defines the what, when, and where of backups. Key resource types include Job, FileSet, Schedule, Client, Storage, and Pool.

# Edit the Director configuration
$ sudo nano /etc/bacula/bacula-dir.conf

# Define a backup job
Job {
  Name = "BackupWebServer"
  Type = Backup
  Level = Incremental
  Client = webserver01-fd
  FileSet = "WebServerFiles"
  Schedule = "WeeklyCycle"
  Storage = File1
  Pool = Default
  Messages = Standard
  Priority = 10
  Write Bootstrap = "/var/lib/bacula/%c.bsr"
}

# Define what files to back up
FileSet {
  Name = "WebServerFiles"
  Include {
    Options {
      signature = MD5
      compression = GZIP
    }
    File = /etc
    File = /var/www
    File = /home
    File = /var/lib/mysql
  }
  Exclude {
    File = /var/www/cache
    File = /tmp
    File = /proc
    File = /sys
  }
}

# Define the backup schedule
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
}

# Define the client (File Daemon)
Client {
  Name = webserver01-fd
  Address = 192.168.1.101
  FDPort = 9102
  Catalog = MyCatalog
  Password = "fd-secret-password"
  File Retention = 60 days
  Job Retention = 6 months
  AutoPrune = yes
}

# Define the storage target
Storage {
  Name = File1
  Address = 192.168.1.100
  SDPort = 9103
  Password = "sd-secret-password"
  Device = FileChgr1
  Media Type = File
  Maximum Concurrent Jobs = 5
}

# Validate the configuration
$ sudo bacula-dir -tc /etc/bacula/bacula-dir.conf
Configuration OK

# Reload the Director
$ sudo systemctl reload bacula-director

Configuring rsnapshot

While Bacula handles enterprise backup orchestration, rsnapshot provides a simpler, filesystem-level snapshot approach. Built on rsync and hard links, rsnapshot creates space-efficient point-in-time copies. Unchanged files are hard-linked between snapshots, meaning only modified files consume additional disk space.

# Install rsnapshot
$ sudo apt install -y rsnapshot

# Edit the configuration (note: rsnapshot requires TABS, not spaces)
$ sudo nano /etc/rsnapshot.conf

# Set the snapshot root directory
snapshot_root	/backup/rsnapshot/

# Use rsync with SSH for remote backups
cmd_ssh	/usr/bin/ssh

# Define retention intervals
retain	hourly	6
retain	daily	7
retain	weekly	4
retain	monthly	3

# Define backup sources
backup	/etc/	localhost/
backup	/home/	localhost/
backup	/var/www/	localhost/
backup	/var/log/	localhost/
backup	root@192.168.1.101:/etc/	webserver01/
backup	root@192.168.1.101:/var/www/	webserver01/

# Exclude patterns
exclude	*.tmp
exclude	/var/www/cache/
exclude	.git/

# Test the configuration
$ sudo rsnapshot configtest
Syntax OK

# Run a manual hourly snapshot
$ sudo rsnapshot hourly

# Verify snapshot structure
$ ls -la /backup/rsnapshot/
drwxr-xr-x  4 root root 4096 Mar  2 06:00 hourly.0
drwxr-xr-x  4 root root 4096 Mar  2 05:00 hourly.1
drwxr-xr-x  4 root root 4096 Mar  2 04:00 hourly.2

# Set up cron jobs for automated rotation
$ sudo tee /etc/cron.d/rsnapshot > /dev/null <<'EOF'
0 */4  * * *  root  /usr/bin/rsnapshot hourly
30 3   * * *  root  /usr/bin/rsnapshot daily
0  3   * * 1  root  /usr/bin/rsnapshot weekly
30 2   1 * *  root  /usr/bin/rsnapshot monthly
EOF

Restore Procedures

A backup is only as good as its restore capability. Regular restore testing is essential to validate that your backups are complete and functional.

# --- Bacula restore via bconsole ---
$ sudo bconsole
*restore
# Select option 5: "Select the most recent backup for a client"
# Choose the client and FileSet
# Mark files for restore:
mark /etc/nginx/nginx.conf
mark /var/www/html/
done
# Confirm restore location (default: /tmp/bacula-restores/)
yes

# Monitor restore progress
*status dir

# --- rsnapshot restore (simply copy files) ---
# Restore a single file from the latest hourly snapshot
$ sudo cp /backup/rsnapshot/hourly.0/localhost/etc/nginx/nginx.conf 
    /etc/nginx/nginx.conf

# Restore an entire directory from a daily snapshot
$ sudo rsync -avz /backup/rsnapshot/daily.2/localhost/var/www/ /var/www/

# Compare a file across snapshots to find when a change occurred
$ diff /backup/rsnapshot/hourly.0/localhost/etc/passwd 
       /backup/rsnapshot/hourly.3/localhost/etc/passwd

Key Takeaways

  • The three backup types — full, incremental, and differential — serve different trade-offs between storage efficiency and restore complexity; the GFS rotation scheme combines them for enterprise use.
  • Bacula’s architecture separates concerns across Director (scheduling), Storage Daemon (media), and File Daemon (client agents), enabling scalable network backup across many hosts.
  • rsnapshot uses rsync and hard links to create space-efficient filesystem snapshots with configurable hourly, daily, weekly, and monthly retention.
  • The 3-2-1 rule (3 copies, 2 media types, 1 off-site) is the minimum standard for data protection against localized disasters.
  • Regular restore testing is non-negotiable — an untested backup is not a backup; validate both file integrity and restore procedures on a scheduled basis.

What’s Next

In the next lesson, we will explore DRBD Block Replication — learning how to replicate block devices across servers in real time for high-availability storage that complements backup with continuous data protection.

繁體中文

概述

  • 您將學到:備份策略(完整/增量/差異)的理論、Bacula 的多元件架構(Director、Storage Daemon、File Daemon)、如何在 bacula-dir.conf 中定義備份作業、如何設定 rsnapshot 進行每小時/每日/每週快照輪替,以及如何執行可靠的還原。
  • 先決條件:系統監控基礎(第 61 課)、日誌管理(第 63 課)、熟悉 cron 排程
  • 預計閱讀時間:20 分鐘

介紹

資料遺失是任何計算環境中最具破壞性的事件之一。無論是由硬體故障、人為錯誤、勒索軟體還是自然災害引起,關鍵資料的遺失都可能導致業務運營停擺,甚至在某些情況下徹底摧毀組織。備份是防止資料遺失的保險策略,與所有保險一樣,必須經過規劃、測試和維護才能有效。

穩健的備份策略遠不止簡單地複製檔案。它涉及理解恢復點目標(RPO)——您能承受多少資料遺失——以及恢復時間目標(RTO)——您必須多快恢復服務。這些業務需求驅動了備份類型、頻率、保留策略和儲存介質的選擇。

在本課程中,我們將探討基本備份概念,然後在 Ubuntu Server 上實作兩個互補的工具:Bacula(企業級網路備份套件)和 rsnapshot(基於 rsync 和硬連結的輕量級檔案系統快照工具)。

備份策略基礎

在選擇工具之前,您必須了解三種主要備份類型及其權衡:

  • 完整備份:複製備份集中的每個檔案。提供最簡單的還原,但消耗最多的儲存空間和時間。通常每週或每月執行。
  • 增量備份:僅複製自上次任何類型備份以來更改的檔案。快速且節省儲存,但還原需要最後一次完整備份加上每個後續增量備份。
  • 差異備份:複製自上次完整備份以來更改的所有檔案。在兩者之間取得平衡——比增量大但還原更簡單。

經典的企業模式是祖父-父親-兒子(GFS)輪替方案:每日增量(兒子)、每週差異或完整(父親)、每月完整長期保留(祖父)。

3-2-1 規則是廣泛接受的最佳實踐:至少維護資料的 3 份副本,存放在 2 種不同的儲存介質上,其中 1 份存放在異地。

Bacula 架構

  • Bacula Director (bacula-dir):中央控制守護程序。排程和監督所有備份、還原和驗證作業。
  • Bacula Storage Daemon (bacula-sd):管理實體儲存介質(磁碟卷、磁帶機)。
  • Bacula File Daemon (bacula-fd):安裝在每台需要備份的機器上的客戶端代理。
  • Bacula Catalog:SQL 資料庫,儲存所有備份作業、卷和檔案位置的中繼資料。
  • Bacula Console (bconsole):與 Director 互動的命令列介面。
# 在 Ubuntu 上安裝 Bacula 元件
$ sudo apt install -y bacula-director bacula-storage bacula-client 
    bacula-console bacula-common-mysql

# 驗證所有守護程序正在運行
$ sudo systemctl status bacula-director
$ sudo systemctl status bacula-sd
$ sudo systemctl status bacula-fd

設定 Bacula Director

# 定義備份作業
Job {
  Name = "BackupWebServer"
  Type = Backup
  Level = Incremental
  Client = webserver01-fd
  FileSet = "WebServerFiles"
  Schedule = "WeeklyCycle"
  Storage = File1
  Pool = Default
}

# 定義備份排程
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
}

# 驗證設定
$ sudo bacula-dir -tc /etc/bacula/bacula-dir.conf

設定 rsnapshot

# 安裝 rsnapshot
$ sudo apt install -y rsnapshot

# 編輯設定(注意:rsnapshot 需要 TAB,不是空格)
$ sudo nano /etc/rsnapshot.conf

snapshot_root	/backup/rsnapshot/
retain	hourly	6
retain	daily	7
retain	weekly	4
retain	monthly	3

backup	/etc/	localhost/
backup	/home/	localhost/
backup	/var/www/	localhost/

# 測試設定
$ sudo rsnapshot configtest

# 設定 cron 自動輪替
0 */4  * * *  root  /usr/bin/rsnapshot hourly
30 3   * * *  root  /usr/bin/rsnapshot daily
0  3   * * 1  root  /usr/bin/rsnapshot weekly
30 2   1 * *  root  /usr/bin/rsnapshot monthly

還原程序

# Bacula 還原
$ sudo bconsole
*restore
# 選擇客戶端和 FileSet,標記要還原的檔案

# rsnapshot 還原(直接複製檔案)
$ sudo cp /backup/rsnapshot/hourly.0/localhost/etc/nginx/nginx.conf 
    /etc/nginx/nginx.conf

# 比較快照間的檔案差異
$ diff /backup/rsnapshot/hourly.0/localhost/etc/passwd 
       /backup/rsnapshot/hourly.3/localhost/etc/passwd

重點總結

  • 三種備份類型——完整、增量和差異——在儲存效率和還原複雜度之間有不同的權衡;GFS 輪替方案為企業使用將它們結合。
  • Bacula 的架構將關注點分離到 Director(排程)、Storage Daemon(介質)和 File Daemon(客戶端代理),實現跨多主機的可擴展網路備份。
  • rsnapshot 使用 rsync 和硬連結建立節省空間的檔案系統快照,具有可設定的每小時、每日、每週和每月保留。
  • 3-2-1 規則(3 份副本、2 種介質、1 份異地)是防護本地災難的最低標準。
  • 定期還原測試不可妥協——未經測試的備份不是備份;應按計劃驗證檔案完整性和還原程序。

下一步

在下一課中,我們將探討 DRBD 區塊複製——學習如何在伺服器之間即時複製區塊裝置,以實現高可用性儲存,並以持續資料保護來補充備份。

日本語

概要

  • 学習内容:バックアップ戦略(フル/増分/差分)の理論、Bacula のマルチコンポーネントアーキテクチャ(Director、Storage Daemon、File Daemon)、bacula-dir.conf でのバックアップジョブの定義、rsnapshot による時間/日/週単位のスナップショットローテーション、信頼性の高いリストア手順。
  • 前提条件:システム監視の基礎(レッスン61)、ログ管理(レッスン63)、cron スケジューリングの基礎知識
  • 推定読了時間:20分

はじめに

データ損失は、あらゆるコンピューティング環境で最も壊滅的なイベントの1つです。ハードウェア障害、人的ミス、ランサムウェア、自然災害のいずれが原因であっても、重要なデータの損失はビジネス運営を停止させ、場合によっては組織を完全に破壊する可能性があります。バックアップはデータ損失に対する保険であり、すべての保険と同様に、有効であるためには計画、テスト、維持が必要です。

堅牢なバックアップ戦略は、単にファイルをコピーするだけではありません。復旧ポイント目標(RPO)— どれだけのデータ損失を許容できるか — と復旧時間目標(RTO)— どれだけ迅速にサービスを復旧しなければならないか — を理解することが含まれます。

このレッスンでは、基本的なバックアップの概念を探り、Ubuntu Server 上で2つの補完的なツールを実装します:エンタープライズグレードのネットワークバックアップスイートである Bacula と、rsync とハードリンクに基づく軽量なファイルシステムスナップショットユーティリティである rsnapshot です。

バックアップ戦略の基礎

  • フルバックアップ:バックアップセット内のすべてのファイルをコピーする。リストアが最も簡単だが、ストレージと時間を最も消費する。通常は週次または月次で実行。
  • 増分バックアップ:前回のバックアップ以降に変更されたファイルのみをコピーする。高速でストレージ効率が良いが、リストアには最後のフルバックアップとすべての後続増分が必要。
  • 差分バックアップ:最後のフルバックアップ以降に変更されたすべてのファイルをコピーする。バランスの取れたアプローチ。

クラシックなエンタープライズパターンは祖父-父-子(GFS)ローテーションスキームです:日次増分(子)、週次差分またはフル(父)、月次フルの長期保持(祖父)。

3-2-1 ルールは広く受け入れられているベストプラクティスです:データの少なくとも3つのコピーを、2つの異なるストレージメディアに、1つはオフサイトに保管します。

Bacula アーキテクチャ

  • Bacula Director (bacula-dir):中央制御デーモン。すべてのバックアップ、リストア、検証ジョブをスケジュールし監督する。
  • Bacula Storage Daemon (bacula-sd):物理ストレージメディア(ディスクボリューム、テープドライブ)を管理する。
  • Bacula File Daemon (bacula-fd):バックアップ対象の各マシンにインストールされるクライアントエージェント。
  • Bacula Catalog:すべてのバックアップジョブ、ボリューム、ファイル位置のメタデータを保存する SQL データベース。
  • Bacula Console (bconsole):Director と対話するためのコマンドラインインターフェース。
# Ubuntu に Bacula コンポーネントをインストール
$ sudo apt install -y bacula-director bacula-storage bacula-client 
    bacula-console bacula-common-mysql

# すべてのデーモンが実行中であることを確認
$ sudo systemctl status bacula-director
$ sudo systemctl status bacula-sd
$ sudo systemctl status bacula-fd

Bacula Director の設定

# バックアップジョブの定義
Job {
  Name = "BackupWebServer"
  Type = Backup
  Level = Incremental
  Client = webserver01-fd
  FileSet = "WebServerFiles"
  Schedule = "WeeklyCycle"
  Storage = File1
  Pool = Default
}

# バックアップスケジュールの定義
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
}

# 設定を検証
$ sudo bacula-dir -tc /etc/bacula/bacula-dir.conf

rsnapshot の設定

# rsnapshot をインストール
$ sudo apt install -y rsnapshot

# 設定を編集(注意:rsnapshot はタブが必要、スペースではない)
$ sudo nano /etc/rsnapshot.conf

snapshot_root	/backup/rsnapshot/
retain	hourly	6
retain	daily	7
retain	weekly	4
retain	monthly	3

backup	/etc/	localhost/
backup	/home/	localhost/
backup	/var/www/	localhost/

# 設定をテスト
$ sudo rsnapshot configtest

# 自動ローテーションのための cron 設定
0 */4  * * *  root  /usr/bin/rsnapshot hourly
30 3   * * *  root  /usr/bin/rsnapshot daily
0  3   * * 1  root  /usr/bin/rsnapshot weekly
30 2   1 * *  root  /usr/bin/rsnapshot monthly

リストア手順

# Bacula リストア
$ sudo bconsole
*restore
# クライアントと FileSet を選択し、リストアするファイルをマーク

# rsnapshot リストア(単純にファイルをコピー)
$ sudo cp /backup/rsnapshot/hourly.0/localhost/etc/nginx/nginx.conf 
    /etc/nginx/nginx.conf

# スナップショット間のファイル差分を比較
$ diff /backup/rsnapshot/hourly.0/localhost/etc/passwd 
       /backup/rsnapshot/hourly.3/localhost/etc/passwd

重要ポイント

  • 3つのバックアップタイプ — フル、増分、差分 — はストレージ効率とリストアの複雑さの間で異なるトレードオフがある。GFS ローテーションスキームはエンタープライズ用にこれらを組み合わせる。
  • Bacula のアーキテクチャは関心事を Director(スケジューリング)、Storage Daemon(メディア)、File Daemon(クライアントエージェント)に分離し、多数のホストにまたがるスケーラブルなネットワークバックアップを可能にする。
  • rsnapshot は rsync とハードリンクを使用してスペース効率の良いファイルシステムスナップショットを作成し、時間/日/週/月単位で設定可能な保持を提供する。
  • 3-2-1 ルール(3つのコピー、2つのメディアタイプ、1つはオフサイト)はローカル災害に対するデータ保護の最低基準である。
  • 定期的なリストアテストは交渉の余地がない — テストされていないバックアップはバックアップではない。ファイルの整合性とリストア手順を定期的に検証すべきである。

次のステップ

次のレッスンでは、DRBD ブロックレプリケーションについて学びます。高可用性ストレージのためにサーバー間でブロックデバイスをリアルタイムにレプリケートし、継続的なデータ保護でバックアップを補完する方法を学びます。

You Missed