ボーグ-重複排除、圧縮、暗号化を備えたLinuxバックアップツール

ボルグバックアップ (別名:Borg)は、圧縮と認証付き暗号化をサポートする重複排除バックアッププログラムです。 ボーグの主な目標は、データをバックアップするための効率的で安全な方法を提供することです。 Borgバックアップで使用されるデータ重複排除技術は、変更のみが保存され、認証された暗号化技術により、完全に信頼されていないターゲットへのバックアップに適しているため、毎日のバックアップに適しています。

この記事では、Ubuntu16およびその他のLinuxフレーバーでのBorgBackupのインストールと使用法について説明します。

ボーグバックアップの主な機能

スペース効率の良いストレージ

→重複排除は、格納されるバイト数を減らすために使用されるコンテンツ定義のチャンクに基づいています。 各ファイルはいくつかの可変長チャンクに分割され、これまでに表示されたことのないチャンクのみがリポジトリに追加されます。

→重複排除するには、同じリポジトリ内のすべてのチャンクが、異なるマシン、以前のバックアップ、同じバックアップ、または同じ単一ファイルからのものであるかどうかに関係なく考慮されます。

→他の重複排除アプローチと比較して、ボーグで使用される方法はに依存しません

•ファイル/ディレクトリ名は同じまま:リポジトリを共有しているマシン間でも、重複排除を強制終了せずにファイルとディレクトリを移動できます。
•完全なファイルまたはタイムスタンプを同じままにする:大きなファイルが少し変更された場合、いくつかの新しいチャンクを保存するだけで済みます。これは、VMまたはrawディスクに最適です。
•ファイル内のデータチャンクの絶対位置:スタッフがシフトされる可能性があり、重複排除アルゴリズムによって検出されます。

スピード

•パフォーマンスクリティカルなコード(チャンキング、圧縮、暗号化)がC / Cythonに実装されています
•ファイル/チャンクインデックスデータのローカルキャッシュ
•変更されていないファイルの迅速な検出

データ暗号化

→すべてのデータは256ビットのAES暗号化を使用して保護でき、データの整合性と信頼性はHMAC-SHA256を使用して検証されます。 データは暗号化されたクライアント側です。

圧縮

→すべてのデータは、lz4(超高速、低圧縮)、zlib(中速および圧縮)、またはlzma(低速、高圧縮)で圧縮できます。

オフサイトバックアップ

→Borgは、SSH経由でアクセス可能な任意のリモートホストにデータを保存できます。 Borgがリモートホストにインストールされている場合、ネットワークファイルシステム(sshfs、nfsなど)を使用する場合と比較して、パフォーマンスを大幅に向上させることができます。

ファイルシステムとしてマウント可能なバックアップ

→バックアップアーカイブは、ユーザースペースファイルシステムとしてマウント可能であり、インタラクティブなバックアップ検査と復元を簡単に行うことができます(通常のファイルマネージャーを使用するなど)。

複数のプラットフォームに簡単にインストール

→何もインストールする必要のない単一ファイルのバイナリを提供しています。これらのプラットフォームで実行できます。

•Linux
Mac OS X
•FreeBSD
•OpenBSDおよびNetBSD(xattrs / ACLsサポートまたはバイナリはまだありません)
•Cygwin(サポートされていません。バイナリはまだありません)
•Windows10のLinuxサブシステム(サポートされていません)

無料のオープンソースソフトウェア

•セキュリティと機能を個別に監査できます
•BSD(3条項)ライセンスの下でライセンス供与されています。完全なライセンスについては、ライセンスを参照してください。

ボーグをインストールする

Ubuntu 16にBorgバックアップをインストールするには、ターミナルで次のコマンドを実行します。

# sudo apt-get install borgbackup borgbackup-doc

ボーグバイナリはからダウンロードすることもできます github PATH環境変数が指す場所に移動します。

# wget https://github.com/borgbackup/borg/releases/download/1.0.10/borg-linux64
# mv borg-linux64 /usr/local/bin/borg
# chmod u+x /usr/local/bin/borg
# chown root:root /usr/local/bin/borg

ボーグの使い方

ボーグはいくつかのコマンドで構成されています。 各コマンドは、いくつかの引数とオプションを受け入れます。 次のセクションでは、各コマンドについて詳しく説明します。

ボーグ初期化

新しいバックアップリポジトリを初期化し、バックアップアーカイブを作成します。

# Local repository (default is to use encryption in repokey mode)
$ borg init /path/to/repo

# Local repository (no encryption)
$ borg init --encryption=none /path/to/repo

# Remote repository (accesses a remote borg via ssh)
$ borg init user@hostname:backup

# Remote repository (store the key your home dir)
$ borg init --encryption=keyfile user@hostname:backup

許可されていないユーザーがバックアップリポジトリにアクセスした場合に備えて、暗号化を使用して保護します。

ボーグ作成

このコマンドは、指定されたすべてのパスを再帰的にトラバースしている間に見つかったすべてのファイルを含むborgバックアップアーカイブを作成します。 パスとして「-」を指定すると、borgは標準入力からデータを読み取り、そのデータから作成されたアーカイブにファイル「stdin」を作成します。 アーカイブは、他のアーカイブにすでに保存されているファイルまたはファイルの一部のためにディスクスペースをほとんど消費しません。

# Backup ~/Documents into an archive named "my-documents"
$ borg create /path/to/repo::my-documents ~/Documents

# same, but verbosely list all files as we process them
$ borg create -v --list /path/to/repo::my-documents ~/Documents

# Backup ~/Documents and ~/src but exclude pyc files
$ borg create /path/to/repo::my-files 
~/Documents                       
~/src                             
--exclude '*.pyc'

# Backup home directories excluding image thumbnails (i.e. only
# /home/*/.thumbnails is excluded, not /home/*/*/.thumbnails)
$ borg create /path/to/repo::my-files /home 
--exclude 're:^/home/[^/]+/.thumbnails/'

# Do the same using a shell-style pattern
$ borg create /path/to/repo::my-files /home 
--exclude 'sh:/home/*/.thumbnails'

# Backup the root filesystem into an archive named "root-YYYY-MM-DD"
# use zlib compression (good, but slow) - default is no compression
$ borg create -C zlib,6 /path/to/repo::root-{now:%Y-%m-%d} / --one-file-system

# Make a big effort in fine granular deduplication (big chunk management
# overhead, needs a lot of RAM and disk space, see formula in internals
# docs - same parameters as borg < 1.0 or attic):
$ borg create --chunker-params 10,23,16,4095 /path/to/repo::small /smallstuff

# Backup a raw device (must not be active/in use/mounted at that time)
$ dd if=/dev/sdx bs=10M | borg create /path/to/repo::my-sdx -

# No compression (default)
$ borg create /path/to/repo::arch ~

# Super fast, low compression
$ borg create --compression lz4 /path/to/repo::arch ~

# Less fast, higher compression (N = 0..9)
$ borg create --compression zlib,N /path/to/repo::arch ~

# Even slower, even higher compression (N = 0..9)
$ borg create --compression lzma,N /path/to/repo::arch ~

# Use short hostname, user name and current time in archive name
$ borg create /path/to/repo::{hostname}-{user}-{now} ~
# Similar, use the same datetime format as borg 1.1 will have as default
$ borg create /path/to/repo::{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S} ~
# As above, but add nanoseconds
$ borg create /path/to/repo::{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S.%f} ~

ボーグエキス

このコマンドは、アーカイブからコンテンツを抽出し、現在のディレクトリに書き込みます。

# Extract entire archive
$ borg extract /path/to/repo::my-files

# Extract entire archive and list files while processing
$ borg extract -v --list /path/to/repo::my-files

# Extract the "src" directory
$ borg extract /path/to/repo::my-files home/USERNAME/src

# Extract the "src" directory but exclude object files
$ borg extract /path/to/repo::my-files home/USERNAME/src --exclude '*.o'

# Restore a raw device (must not be active/in use/mounted at that time)
$ borg extract --stdout /path/to/repo::my-sdx | dd of=/dev/sdx bs=10M

ボーグチェック

checkコマンドは、リポジトリと対応するアーカイブの整合性を検証します。

# check for corrupt chunks / segments:
borg check -v --repository-only REPO
# repair the repo:
borg check -v --repository-only --repair REPO
# make sure everything is fixed:
borg check -v --repository-only REPO

ボーグの名前を変更

このコマンドは、リポジトリ内のアーカイブの名前を変更します。

$ borg create /path/to/repo::archivename ~
$ borg list /path/to/repo
archivename                          Mon, 2017-03-06 19:50:19

$ borg rename /path/to/repo::archivename newname
$ borg list /path/to/repo
newname                              Mon, 2017-03-06 19:52:19

ボーグリスト

このコマンドは、リポジトリまたはアーカイブの内容を一覧表示します。

$ borg list /path/to/repository
$ borg list /path/to/repo::root-2017-03-06
$ borg list /path/to/repo::archiveA --list-format="{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NEWLINE}"
# see what is changed between archives, based on file modification time, size and file path
$ borg list /path/to/repo::archiveA --list-format="{mtime:%s}{TAB}{size}{TAB}{path}{LF}" |sort -n > /tmp/list.archiveA
$ borg list /path/to/repo::archiveB --list-format="{mtime:%s}{TAB}{size}{TAB}{path}{LF}" |sort -n > /tmp/list.archiveB
$ diff -y /tmp/list.archiveA /tmp/list.archiveB

ボーグ削除

このコマンドは、リポジトリまたは完全なリポジトリからアーカイブを削除します。 それに応じてディスク容量が再利用されます。 リポジトリ全体を削除すると、そのリポジトリのローカルキャッシュ(存在する場合)も削除されます。

# delete a single backup archive:
$ borg delete /path/to/repo::Monday

# delete the whole repository and the related local cache:
$ borg delete /path/to/repo
You requested to completely DELETE the repository *including* all archives it contains:
repo                                 Mon, 2017-03-06 19:26:54
root-2017-03-06                      Mon, 2017-03-06 19:50:29
newname                              Mon, 2017-03-06 19:52:19
Type 'YES' if you understand this and want to continue: YES

ボーグプルーン

pruneコマンドは、指定された保持オプションのいずれにも一致しないすべてのアーカイブを削除することにより、リポジトリを削除します。 このコマンドは通常、特定の数の履歴ボルグバックアップを保持したい自動バックアップスクリプトによって使用されます。

# Keep 7 end of day and 4 additional end of week archives.
# Do a dry-run without actually deleting anything.
$ borg prune -v --list --dry-run --keep-daily=7 --keep-weekly=4 /path/to/repo

# Same as above but only apply to archive names starting with the hostname
# of the machine followed by a "-" character:
$ borg prune -v --list --keep-daily=7 --keep-weekly=4 --prefix='{hostname}-' /path/to/repo

# Keep 7 end of day, 4 additional end of week archives,
# and an end of month archive for every month:
$ borg prune -v --list --keep-daily=7 --keep-weekly=4 --keep-monthly=-1 /path/to/repo

# Keep all backups in the last 10 days, 4 additional end of week archives,
# and an end of month archive for every month:
$ borg prune -v --list --keep-within=10d --keep-weekly=4 --keep-monthly=-1 /path/to/repo

ボーグ情報

このコマンドは、指定されたアーカイブに関する詳細情報を表示します。

$ borg info /path/to/repo::root-2017-03-06

ボーグマウント

このコマンドは、アーカイブをFUSEファイルシステムとしてマウントします。 これは、アーカイブを参照したり、個々のファイルを復元したりする場合に役立ちます。

$ borg mount /path/to/repo::root-2017-03-06 /tmp/mymountpoint
$ ls /tmp/mymountpoint

ボーグumount

このコマンドは、borgmountでマウントされたFUSEファイルシステムをアンマウントします。

$ borg umount /tmp/mymountpoint

ボーグキーのエクスポート

リポジトリ暗号化が使用されている場合、キーがないとリポジトリにアクセスできません。 このコマンドを使用すると、この重要なキーをバックアップできます。

$ borg key export /path/to/repo /path/to/export

ボーグキーのインポート

このコマンドを使用すると、以前にexportコマンドでバックアップしたキーを復元できます。

$ borg key import /path/to/repo /path/to/import

ボーグチェンジパスフレーズ

リポジトリの暗号化に使用されるキーファイルは、オプションでパスフレーズで保護されています。 このコマンドを使用して、このパスフレーズを変更できます。

# Create a key file protected repository
$ borg init --encryption=keyfile -v /path/to/repo
Initializing repository at "/path/to/repo"
Enter new passphrase:
Enter same passphrase again:
Remember your passphrase. Your data will be inaccessible without it.
Key in "/root/.config/borg/keys/mnt_backup" created.
Keep this key safe. Your data will be inaccessible without it.
Synchronizing chunks cache...
Archives: 0, w/ cached Idx: 0, w/ outdated Idx: 0, w/o cached Idx: 0.
Done.

# Change key file passphrase
$ borg change-passphrase -v /path/to/repo
Enter passphrase for key /root/.config/borg/keys/mnt_backup:
Enter new passphrase:
Enter same passphrase again:
Remember your passphrase. Your data will be inaccessible without it.
Key updated

ボーグサーブ

このコマンドは、リポジトリサーバープロセスを開始します。 このコマンドは通常、手動では使用されません。

# Allow an SSH keypair to only run borg, and only have access to /path/to/repo.
# Use key options to disable unneeded and potentially dangerous SSH functionality.
# This will help to secure an automated remote backup system.
$ cat ~/.ssh/authorized_keys
command="borg serve --restrict-to-path /path/to/repo",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc ssh-rsa AAAAB3[...]

ボーグのアップグレード

既存のBorgバックアップリポジトリをアップグレードします。

$ borg upgrade --tam REPO

ボーグブレークロック

このコマンドは、リポジトリとキャッシュのロックを解除します。 慎重に、そして(どのマシンの)ボーグプロセスもキャッシュまたはリポジトリにアクセスしようとしていないときにのみ使用してください。

$ borg break-lock /path/to/repo

結論

ボーグはPythonで書かれており、他の従来のバックアップソリューションに比べて多くの利点があります。 データの重複排除と暗号化は2つの機能です。 ほとんどのLinuxディストリビューションには、すでに公式リポジトリにあります。 クライアントはSSHを使用してサーバーに接続するため、バックアップサーバーの構成は簡単です。 したがって、単一のborgユーザーをセットアップし、クライアントを少し制限したい場合があります。