「Restic」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
52行目: 52行目:
   
 
もちろん、将来の追加のインクリメンタルな変更に対してスペースが必要ですので、バックアップされるデータのサイズの 2 倍、または 3 倍のボリュームを作成することが良いです。例えば、 {{ic|/}} が {{ic|55G}} を占めている場合、 {{ic|/mnt/restic}} を {{ic|110G}} で作成できます。
 
もちろん、将来の追加のインクリメンタルな変更に対してスペースが必要ですので、バックアップされるデータのサイズの 2 倍、または 3 倍のボリュームを作成することが良いです。例えば、 {{ic|/}} が {{ic|55G}} を占めている場合、 {{ic|/mnt/restic}} を {{ic|110G}} で作成できます。
 
==== Systemd Service ====
 
 
You will need a service unit. [[Create]] one:
 
 
{{hc|/etc/systemd/system/restic-backup.service|2=
 
[Unit]
 
Description=Backup system
 
 
[Service]
 
ExecStart=/usr/local/bin/restic-backup
 
}}
 
 
{{Note|The service will be invoked by the timer below but can also be [[start]]ed on demand for any unplanned snapshots.}}
 
   
 
==== Systemd サービス ====
 
==== Systemd サービス ====

2023年9月1日 (金) 18:34時点における版

関連記事

このページでは、Arch Linux の文脈でのクイックスタートガイドを提供し、最良の方法を提案するための restic [1] バックアップツールについて説明します。

主な機能と利点は以下の通りです。

  • 暗号化されたバックアップ
  • リモートバックアップ
  • 圧縮のための組み込みサポート
  • 効率的なストレージ (チャンクベースのインクリメント、データは複製されません)
  • cron や systemd などのカスタムスケジューリングソリューションを使用する柔軟性
  • go で書かれているおり、スタンドアロンのバイナリ

インストール

resticインストールし、その後、空のディレクトリでリポジトリを初期化します (ローカルバックアップ用) :

$ restic init --repo /path/to/backup/directory/

公式チュートリアル [2] を参照してください。

セキュリティ

Restic はリポジトリの対称暗号化を使用します。これは、自動化されたプロセスがバックアップを作成できるように、一般的にキーをプレーンテキストで保存する必要があるため、バックアップにいくつかの問題をもたらします [3] [4]

Restic は、key vault などからパスワードを取得するスクリプトのアイデアをサポートしています。ただし、key vault やシークレットストアのロックを解除するためにも、おそらくどこかで資格情報をハードコードする必要があるでしょう。理想的には、公開鍵を使用してスナップショットを作成し (restic によって自動化されたスクリプトで使用される) 、プライベートキーでのみスナップショットを復号化できる非対称暗号化があると良いですが、これはサポートされていません。

この問題を回避するために、リポジトリのパスワードを LUKS 暗号化ボリューム上のファイルに保存できます。ボリュームは、ユーザーが提供する YubiKey などのパスフレーズや FIDO キー ( Universal 2nd Factor 参照) を使用して、起動時に復号化されます。crypttab ( dm-crypt 参照) および fstab で設定できます。

ノート: Restic リポジトリ (バックアップ) は、LUKS で暗号化する必要はありません。Restic はデフォルトでデータを暗号化します。

スケジューリング

Systemd タイマー

timeshift [5] などの他のツールとは異なり、restic にはスケジューリング機能が含まれていません。cron または systemd タイマー を使用することが期待されています。

restic-automatic-backup-scheduler などの準備されたプロジェクトを使用するか、この例に従って、ローカル (完全) システムバックアップを作成し、root ユーザー として実行する必要があります。

この例では、既存の restic リポジトリが初期化された既存のディレクトリがあると想定されています ( #インストール参照)。

別のボリュームを作成する

この手順はオプションですが、自動バックアッププロセスが OS に利用可能なスペースをすべて消費する可能性があるため、そこに別のボリュームをマウントすることが良いです。

最初の restic バックアップは、OS 全体をクローンする必要があるため、必要な最小のスペースは、OS によって占められるスペース (以下で説明するパスの除外に対して) 、またはバックアップを決定した他のディレクトリに等しいです。

もちろん、将来の追加のインクリメンタルな変更に対してスペースが必要ですので、バックアップされるデータのサイズの 2 倍、または 3 倍のボリュームを作成することが良いです。例えば、 /55G を占めている場合、 /mnt/restic110G で作成できます。

Systemd サービス

サービスユニットが必要なので、作成します。

/etc/systemd/system/restic-backup.service
[Unit]
Description=Backup system

[Service]
ExecStart=/usr/local/bin/restic-backup
ノート: サービスは以下のタイマーによって呼び出されますが、予定外のスナップショットについては、オンデマンドで 開始することもできます。
リソース制約の設定

systemd を使用すると、バックアッププロセスにリソース制約を設定するオプションがあります。例えば、メモリと / または CPU の量を制限できます。これは systemd サービスユニットで設定するものです。systemd.resource-control(5) を参照してください。

restic が使用するリソースを制約する別の方法は、公式ドキュメント で説明されているように、 GOMAXPROCS 環境変数を使用することです。

Systemd timer

You will also need a timer unit (this one runs every 15 min):

/etc/systemd/system/restic-backup.timer
[Unit]
Description=Timer for full system backups

[Timer]
OnBootSec=5min
OnUnitActiveSec=15min
Unit=restic-backup.service

[Install]
WantedBy=timers.target

Backup script

You will also want to create a small shell script to pass in all the required options, for example:

/usr/local/bin/restic-backup
#!/bin/bash

if [[ -n $(pgrep 'restic' | grep 'restic backup') ]]; then
  echo 'restic is already running...' 1>&2
  exit 0
fi

set -e
set -v

export RESTIC_REPOSITORY='/mnt/restic'
export RESTIC_PASSWORD_COMMAND='/usr/local/bin/get-restic-password'
export RESTIC_COMPRESSION='off'
export RESTIC_CACHE_DIR=~/.cache/restic

mkdir -p "${RESTIC_CACHE_DIR}"

restic unlock 
restic backup / --exclude-file=/etc/restic/excludes.txt --tag scheduled 
restic check --with-cache --read-data-subset=5G
restic forget --prune --keep-hourly 24 --keep-daily 30 --keep-monthly 6 --keep-weekly 4 --keep-yearly 3
/usr/local/bin/get-restic-password
#!/bin/bash
echo VerySecurePassword123
# chmod 744 /usr/local/bin/restic-backup
# chmod 700 /usr/local/bin/get-restic-password
Compression

If you are using the Btrfs filesystem with compression (e.g. compressテンプレート:=zstd) it will not make sense to encrypt the data again as there is limited gain in re-compressing compressed data (it will just make the backups slower). On the other hand if you are using ext4, you might want to enable compression in restic to save space.

Snapshot retention

Adjust the restic forget --prune --keep-hourly 24 --keep-daily 30 --keep-monthly 6 --keep-weekly 4 --keep-yearly 3 values in the script above if wanted.

Configuring niceness

You may also wish to tweak niceness of the backup process. If you are running backups often you will likely want to reduce the resource usage to prevent it from affecting interactive use. However, you should check how long the backups are taking and make sure they are not overlapping (i.e. a new backup being started when the previous one has not finished).

You can do that with nice(1). You may want to adjust the backup scrip by adding nice to the beginning of the resource intensive commands e.g.:

# nice -n 19 restic backup ...
# nice -n 19 restic check ...

Alternatively if you are using ananicy-cppAUR you may want to ensure that the niceness is configured in its configuration file(s) under /etc/ananicy.d/.

/etc/ananicy.d/00-types.types
{"type":"file-sync","nice":19,"ionice":7}
/etc/ananicy.d/99-custom/file-sync/restic.rules
{"name": "restic", "type": "file-sync"}

Refer to the restic FAQ for more information.

Excludes list

Add the excludes file under /etc/restic e.g.:

/etc/restic/excludes.txt
/data/**
/dev/**
/home/*/**/*.pyc
/home/*/**/__pycache__/**
/home/*/**/node_modules/**
/home/*/.cache/**
/home/*/.local/lib/python*/site-packages/**
/home/*/.mozilla/firefox/*/Cache/**
/lost+found/**
/media/**
/mnt/**
/proc/**
/root/**
/run/**
/swapfile
/sys/**
/tmp/**
/var/cache/**
/var/cache/pacman/pkg/**
/var/lib/docker/**
/var/lib/libvirt/**
/var/lock/**
/var/log/**
/var/run/**

Enable

Do not forget to enable the restic-backup.timer.