Duplicity

提供: ArchWiki
2017年1月17日 (火) 22:15時点におけるKusakata (トーク | 投稿記録)による版 (翻訳)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

Duplicity はネットワークバックアッププログラムです。

ディレクトリやファイルのスナップショットを GnuPG で暗号化されたリモートの tar ファイルに保存することができ、ファイルをバックアップリポジトリとして使用します。リモートのバックアップリポジトリと接続するのに使えるプロトコルは次のとおりです: rsync, ftp, HSI, WebDAV, Tahoe-LAFS, Amazon S3。

バックアップは差分で実行されるため、(最後のバックアップから) ファイルの変更した部分だけが保存されます。

インストール

公式リポジトリから duplicity パッケージをインストールしてください。さらに、以下のフロントエンドが存在します:

  • duply - シェルフロントエンド。AUR からインストールできます。
  • deja-dup - 使いやすいフロントエンド。公式リポジトリからインストールできます。コマンドラインツールの deja-dupGTK+ フロントエンドの deja-dup-preferences が含まれています。

基本的な使用方法

バックアップの実行

scp/ssh プロトコルを使ってローカルフォルダの /home/me をリモートの other.host 内の /usr/backup にバックアップする場合:

$ duplicity /home/me scp://uid@other.host//usr/backup

上記のコマンドを初めて実行したときは、完全なバックアップが作成されます。同じコマンドをもう一度実行すると、既存のバックアップリポジトリに差分バックアップが行われます。

コマンドラインオプションを追加することで以下のようなことができます:

  • バックアップから特定のファイルやディレクトリを追加・除外 (シェルパターンや正規表現が使えます)。
  • 暗号化の設定やバックアップの署名。

バックアップからファイルを復元

other.host のリモートリポジトリ /usr/backup に保存されている最後のスナップショットからローカルフォルダの /home/me を復元したい場合:

$ duplicity scp://uid@other.host//usr/backup /home/me 

上記のコマンドはバックアップの際に使用するコマンドと順番が逆になっています。URL 引数は常にバックアップリポジトリとして扱われ、ローカルパス引数は同期するディレクトリとして扱われます (ローカルのバックアップリポジトリを指定したいときは file:// プロトコルを付けて指定する必要があります)。

コマンドラインオプションを追加することで以下のようなことができます:

  • リポジトリ全体ではなく特定のファイルだけ復元。
  • 特定時刻の状態にファイルを復元。

メンテナンス

リポジトリの状態をローカルファイルと比較することができるコマンドラインオプションが存在します。また、古いスナップショットを削除したり、一定のスナップショットだけを確保したり、指定した時間よりも新しいスナップショットだけ残すこともできます。

詳しくは man ページを見てください。

サンプルバックアップスクリプト

#!/bin/sh
## Remote backup script. Requires duplicity and gpg-agent with the keys and passphrases loaded as root.
## Uses separate encryption and signing keys
## Usage:  'backup_remote.sh'

enc_key=44D79E41
sign_key=F5C978E3
src="/mnt/backup/"
dest="scp://destination.com//backups/homeserver"

# Keychain is used to source the ssh-agent keys when running from a cron job
type -P keychain &>/dev/null || { echo "I require keychain but it's not installed.  Aborting." >&2; exit 1; }
eval `keychain --eval web_rsa` || exit 1
## Note: can't use keychain for gpg-agent because it doesn't currently (2.7.1) read in all the keys correctly. 
## Gpg will ask for a passphrase twice for each key...once for encryption/decryption and once for signing. 
## This makes unattended backups impossible, especially when trying to resume an interrupted backup.
if [ -f "${HOME}/.gnupg/gpg-agent-info" ]; then
      . "${HOME}/.gnupg/gpg-agent-info"
      export GPG_AGENT_INFO
fi

duplicity --use-agent \
         --verbosity notice \
         --encrypt-key "$enc_key" \
         --sign-key "$sign_key" \
         --full-if-older-than 60D \
         --num-retries 3 \
         --asynchronous-upload \
         --volsize 100 \
         --archive-dir /root/.cache/duplicity \
         --log-file /var/log/duplicity.log \
         --exclude /mnt/backup/fsarchiver \
         --exclude '**rdiff-backup-data' \
         "$src" "$dest"
ノート:
  • There is an issue with the current version of pinentry (0.8.1-3) that will not allow passphrase entry for a root gpg-agent when logged in as root using su - or sudo. If you are accessing a remote server where direct root ssh login is not allowed (or desired!), then you have to either patch pinentry or chown root `tty` before running pinentry. This is not an issue when running gpg-agent as a non-root user.
  • If you want to start gpg-agent on root login and then cache the passphrases for gpg-agent at your convenience, you can add these functions to your /root/.bashrc:
function gpg_start {
       gnupginf="${HOME}/.gnupg/gpg-agent-info"
       if pgrep -u "${USER}" gpg-agent >/dev/null 2>&1; then
           eval "$(cat $gnupginf)"
           eval "$(cut -d= -f1 < $gnupginf | xargs echo export)"
       else
           eval "$(gpg-agent -s --daemon --write-env-file $gnupginf)"
       fi
}
function keys {
       touch test-gpg.txt
       touch test-gpg.txt1
       gpg -r 'Duplicity Encryption Key' -e test-gpg.txt
       gpg -r 'Duplicity Signature Key' -e test-gpg.txt1
       gpg -u <signing key> --detach-sign test-gpg.txt
       gpg -u <encryption key> --detach-sign test-gpg.txt1
       gpg -d test-gpg.txt.gpg
       gpg -d test-gpg.txt1.gpg
       rm test-gpg.txt*
}
gpg_start

トラブルシューティング

“inappropriate ioctl for device” というような GPG のエラーが発生する場合、GPG のバージョン 2.1 以上から変わった GPG エージェントの挙動が原因です。詳しくは こちらのスレッド を見てください。基本的には GPG エージェントにパスフレーズを渡すためにプログラムを明示的に許可する必要があります。

問題を解決するGnuPG#無人のパスフレーズに手順が載っています。

参照