バックアップとリカバリ
データのバックアップは、システム管理の最も重要な側面の 1 つです。この記事では、ニーズに合った適切なツールを選択できるように、Ubuntu 26.04 のさまざまなバックアップおよび回復ソリューションを紹介します。
rsync - 柔軟な同期ツール
rsync は、増分転送をサポートする高速で柔軟なファイル同期ツールであり、Linux で最も一般的に使用されるバックアップ ツールの 1 つです。
基本的な使い方
# Local directory sync
rsync -av /source/directory/ /backup/directory/
# Note: the trailing slash on the source path matters
# /source/dir/ -> syncs the contents of the directory
# /source/dir -> syncs the directory itself (including the directory name)共通オプション
# -a archive mode (preserves permissions, timestamps, symlinks, etc.)
# -v verbose output
# -z compress during transfer
# -h human-readable output
# --progress show progress
# --delete delete files in the target that don't exist in the source
# Complete local backup command
rsync -avh --progress /home/user/ /backup/home-user/
# Backup with exclusion rules
rsync -avh --progress \
--exclude='.cache' \
--exclude='node_modules' \
--exclude='.local/share/Trash' \
/home/user/ /backup/home-user/
# Using an exclude file
rsync -avh --exclude-from='/home/user/rsync-excludes.txt' \
/home/user/ /backup/home-user/リモートバックアップ
# Backup to a remote server via SSH
rsync -avz -e ssh /home/user/ user@remote:/backup/home-user/
# Specify SSH port
rsync -avz -e "ssh -p 2222" /home/user/ user@remote:/backup/home-user/
# Restore from a remote server
rsync -avz user@remote:/backup/home-user/ /home/user/
# Use --delete to keep both sides in sync
rsync -avz --delete /home/user/ user@remote:/backup/home-user/自動化されたrsyncバックアップスクリプト
バックアップ スクリプトを作成します。
sudo nano /usr/local/bin/daily-backup.sh#!/bin/bash
# Configuration
SOURCE="/home/"
DEST="/backup/daily"
LOG="/var/log/backup.log"
DATE=$(date +%Y-%m-%d_%H%M%S)
# Create log entry
echo "===== Backup started: $DATE =====" >> "$LOG"
# Execute backup
rsync -avh --delete \
--exclude='.cache' \
--exclude='node_modules' \
--exclude='.local/share/Trash' \
"$SOURCE" "$DEST" >> "$LOG" 2>&1
# Record result
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $(date)" >> "$LOG"
else
echo "Backup failed: $(date)" >> "$LOG"
fisudo chmod +x /usr/local/bin/daily-backup.shcron でスケジュールを設定します。
# Run backup every day at 2 AM
sudo crontab -e
# Add: 0 2 * * * /usr/local/bin/daily-backup.shタイムシフト - システム スナップショット
タイムシフトは、Windows システムの復元と同様に、システム ファイルのスナップショットと回復に重点を置いています。
インストールと構成
# Install Timeshift
sudo apt install timeshift
# Launch the graphical interface
sudo timeshift-gtk
# Create a snapshot via command line
sudo timeshift --create --comments "Before installing NVIDIA driver"
# List all snapshots
sudo timeshift --list
# Restore to a specific snapshot
sudo timeshift --restore --snapshot '2026-03-24_10-00-00'
# Delete a snapshot
sudo timeshift --delete --snapshot '2026-03-24_10-00-00'コマンドライン構成
# View current configuration
sudo timeshift --config
# Set snapshot type (RSYNC or BTRFS)
sudo timeshift --snapshot-device /dev/sda2タイムシフト設定ファイル
/etc/timeshift/timeshift.json を編集します:
{
"backup_device_uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"parent_device_uuid": "",
"do_first_run": false,
"btrfs_mode": false,
"include_btrfs_home": false,
"schedule_monthly": false,
"schedule_weekly": true,
"schedule_daily": true,
"schedule_hourly": false,
"schedule_boot": false,
"count_monthly": 2,
"count_weekly": 3,
"count_daily": 5,
"count_hourly": 0,
"count_boot": 0,
"exclude": [
"/home/**",
"/root/**"
]
}Btrfs スナップショット モード
システムが Btrfs ファイルシステムを使用している場合、Timeshift はネイティブ Btrfs スナップショットを利用できます。これにより、より高速で使用するスペースが少なくなります。
# Verify filesystem type
df -T /
# If it's Btrfs, select BTRFS mode in Timeshift
sudo timeshift --btrfsDeja Dup - デスクトップバックアップツール
Deja Dup (GNOME Backups) は、個人ユーザーに適した、Ubuntu デスクトップ環境用の使いやすいバックアップ ツールです。
インストールと使用方法
# Install (usually pre-installed on Ubuntu Desktop)
sudo apt install deja-dupDeja Dup は、「設定」からアクセスするか、アプリ メニューで「バックアップ」を検索することでアクセスできるグラフィカル インターフェイスを提供します。
主な特徴:
- ローカルディスク、外部ドライブ、ネットワークストレージへのバックアップをサポート
- Google Driveやその他のクラウドストレージへのバックアップをサポート
- バックアップの自動暗号化
- 増分バックアップのサポート
- スケジュールされた自動バックアップ
コマンドライン操作
Deja Dup はバックエンドとして二重性を使用します。
# Manually run a backup
deja-dup --backup
# Restore files
deja-dup --restoreディスクイメージのバックアップ
dd を使用したディスク イメージの作成
# Create a full disk image
sudo dd if=/dev/sda of=/backup/sda.img bs=4M status=progress
# Compressed image
sudo dd if=/dev/sda bs=4M status=progress | gzip > /backup/sda.img.gz
# Restore from an image
sudo dd if=/backup/sda.img of=/dev/sda bs=4M status=progress
# Restore from a compressed image
gunzip -c /backup/sda.img.gz | sudo dd of=/dev/sda bs=4M status=progressClonezilla の使用
Clonezilla は、強力なディスク クローン作成およびイメージング ツールです。
# Install Clonezilla
sudo apt install clonezilla
# It is generally recommended to boot from a Clonezilla Live USB
# Download: https://clonezilla.org/downloads.phptarを使用したシステムバックアップ
# Back up the entire system (excluding unnecessary directories)
sudo tar czpf /backup/system-$(date +%Y%m%d).tar.gz \
--exclude=/backup \
--exclude=/proc \
--exclude=/sys \
--exclude=/dev \
--exclude=/run \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/media \
--exclude=/lost+found \
/
# Restore the system
sudo tar xzpf /backup/system-20260324.tar.gz -C /データベースのバックアップ
MySQL / マリアDB
# Back up a single database
mysqldump -u root -p database_name > /backup/db-$(date +%Y%m%d).sql
# Back up all databases
mysqldump -u root -p --all-databases > /backup/all-db-$(date +%Y%m%d).sql
# Restore a database
mysql -u root -p database_name < /backup/db-20260324.sqlPostgreSQL
# Back up a single database
sudo -u postgres pg_dump dbname > /backup/pg-$(date +%Y%m%d).sql
# Back up all databases
sudo -u postgres pg_dumpall > /backup/pg-all-$(date +%Y%m%d).sql
# Restore
sudo -u postgres psql dbname < /backup/pg-20260324.sqlバックアップ戦略の推奨事項
3-2-1 バックアップ ルール
- データの ** 3** コピー (オリジナル + 2 つのバックアップ)
- 2 異なるストレージ メディア (例: ローカル ハード ドライブ + クラウド ストレージ)
- 1 オフサイト バックアップ (物理的災害からの保護)
シナリオ別の推奨事項
| シナリオ | 推奨ツール | バックアップの頻度 |
|---|---|---|
| デスクトップ個人ユーザー | デジャ・ダップ + タイムシフト | 毎日 / 毎週 |
| 開発ワークステーション | rsync + タイムシフト | 毎日 |
| ウェブサーバー | rsync + データベースバックアップ | 毎日/時間ごと |
| 重要なビジネスサーバー | rsync + LVM スナップショット + オフサイトバックアップ | リアルタイム / 時間ごと |
バックアップの検証
バックアップの整合性を定期的に検証することが不可欠です。
# Verify a tar backup
tar tzf /backup/system-20260324.tar.gz > /dev/null
# Verify an rsync backup
rsync -avhn --delete /source/ /backup/ # dry-run to compare differences
# Perform periodic restore drills