【duplicityインストール】
duplicityは個人データのバックアップとして使えるツールです。
■特徴は3つ
・バックアップ中の履歴を古い状態から新しい状態への増分で記録し、複数のフルバックアップも取れる
・GnuPGを使って暗号化する機能がある
・SSH以外のネットワーク機能にも対応している(FTPやWebDAV,S3など)
今回はFTPでの接続が必要だったのでduplicityを選びました。
■今回のサーバのバージョン
# cat /etc/redhat-release
CentOS release 6.3 (Final)
以下からインストールの説明
■最新のバージョンをダウンロードしてくる(2012/12/21の時点では0.6.20)
# pwd
/root/tmp
# mkdir tmp
# cd tmp/
# wget http://code.launchpad.net/duplicity/0.6-series/0.6.20/+download/duplicity-0.6.20.tar.gz
--2012-12-21 19:56:24-- http://code.launchpad.net/duplicity/0.6-series/0.6.20/+download/duplicity-0.6.20.tar.gz
code.launchpad.net をDNSに問いあわせています... 91.189.89.224, 91.189.89.225
code.launchpad.net|91.189.89.224|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: https://code.launchpad.net/duplicity/0.6-series/0.6.20/+download/duplicity-0.6.20.tar.gz [続く]
--2012-12-21 19:56:24-- https://code.launchpad.net/duplicity/0.6-series/0.6.20/+download/duplicity-0.6.20.tar.gz
code.launchpad.net|91.189.89.224|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Moved Temporarily
場所: https://launchpadlibrarian.net/121487466/duplicity-0.6.20.tar.gz [続く]
--2012-12-21 19:56:26-- https://launchpadlibrarian.net/121487466/duplicity-0.6.20.tar.gz
launchpadlibrarian.net をDNSに問いあわせています... 91.189.89.228, 91.189.89.229
launchpadlibrarian.net|91.189.89.228|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1142460 (1.1M) [application/x-tar]
`duplicity-0.6.20.tar.gz' に保存中
100%[===================================================================================================================>] 1,142,460 149K/s 時間 8.6s
2012-12-21 19:56:36 (130 KB/s) - `duplicity-0.6.20.tar.gz' へ保存完了 [1142460/1142460]
■python-devel,libsync-devel,libsyncを入れる(epelリポジトリ使用)
# yum install python-devel librsync-devel librsync
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/metalink | 5.6 kB 00:00
* base: ftp.tsukuba.wide.ad.jp
* epel: ftp.tsukuba.wide.ad.jp
* extras: ftp.tsukuba.wide.ad.jp
* updates: ftp.tsukuba.wide.ad.jp
base | 3.7 kB 00:00
epel | 4.3 kB 00:00
epel/primary_db | 4.1 MB 00:00
extras | 3.5 kB 00:00
extras/primary_db | 24 kB 00:00
jenkins | 951 B 00:00
jenkins/primary | 18 kB 00:00
jenkins 167/167
updates | 3.5 kB 00:00
updates/primary_db | 4.3 MB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package librsync.i686 0:0.9.7-15.el6 will be installed
---> Package librsync-devel.i686 0:0.9.7-15.el6 will be installed
---> Package python-devel.i686 0:2.6.6-29.el6_3.3 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Installing:
librsync i686 0.9.7-15.el6 epel 44 k
librsync-devel i686 0.9.7-15.el6 epel 12 k
python-devel i686 2.6.6-29.el6_3.3 updates 167 k
Transaction Summary
=============================================================================================================================================================
Install 3 Package(s)
Total download size: 223 k
Installed size: 564 k
Is this ok [y/N]: y
Downloading Packages:
(1/3): librsync-0.9.7-15.el6.i686.rpm | 44 kB 00:00
(2/3): librsync-devel-0.9.7-15.el6.i686.rpm | 12 kB 00:00
(3/3): python-devel-2.6.6-29.el6_3.3.i686.rpm | 167 kB 00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 514 kB/s | 223 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : librsync-0.9.7-15.el6.i686 1/3
Installing : librsync-devel-0.9.7-15.el6.i686 2/3
Installing : python-devel-2.6.6-29.el6_3.3.i686 3/3
Verifying : python-devel-2.6.6-29.el6_3.3.i686 1/3
Verifying : librsync-0.9.7-15.el6.i686 2/3
Verifying : librsync-devel-0.9.7-15.el6.i686 3/3
Installed:
librsync.i686 0:0.9.7-15.el6 librsync-devel.i686 0:0.9.7-15.el6 python-devel.i686 0:2.6.6-29.el6_3.3
Complete!
■duplicityのtar.gzを展開してコンパイルしてインストールする
# tar -xzvf duplicity-0.6.20.tar.gz
duplicity-0.6.20/
duplicity-0.6.20/po/
duplicity-0.6.20/po/LINGUAS
duplicity-0.6.20/po/de/
duplicity-0.6.20/po/de/de.po
・・・・
# cd duplicity-0.6.20
# ll
合計 292
-rw------- 1 1000 1000 67959 10月 28 21:23 2012 CHANGELOG
-rw------- 1 1000 1000 17987 10月 28 21:23 2012 COPYING
-rw------- 1 1000 1000 160119 10月 28 21:23 2012 Changelog.GNU
-rw------- 1 1000 1000 2759 10月 28 21:23 2012 README
-rw------- 1 1000 1000 1225 10月 28 21:23 2012 README-LOG
-rw------- 1 1000 1000 809 10月 28 21:23 2012 README-REPO
drwxr-xr-x 2 1000 1000 4096 10月 28 21:23 2012 bin
drwxr-xr-x 2 1000 1000 4096 10月 28 21:23 2012 dist
drwxr-xr-x 3 1000 1000 4096 10月 28 21:23 2012 duplicity
drwxr-xr-x 27 1000 1000 4096 10月 28 21:23 2012 po
-rwxr-xr-x 1 1000 1000 3233 10月 28 21:23 2012 setup.py
-rw------- 1 1000 1000 102 10月 28 21:23 2012 tarfile-CHANGES
-rw------- 1 1000 1000 2814 10月 28 21:23 2012 tarfile-LICENSE
drwxr-xr-x 6 1000 1000 4096 10月 28 21:23 2012 testing
[root@192 duplicity-0.6.20]# python ./setup.py build
running build
running build_py
creating build
creating build/lib.linux-i686-2.6
creating build/lib.linux-i686-2.6/duplicity
・・・
[root@192 duplicity-0.6.20]# python ./setup.py install
running install
running build
running build_py
running build_ext
running build_scripts
・・・
■duplicityのバージョンを確認してみる。
# duplicity --version
duplicity 0.6.20
■FTPも利用する場合はncftpもインストールする(epelリポジトリ使用)
# yum search ncftp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tsukuba.wide.ad.jp
* epel: ftp.tsukuba.wide.ad.jp
* extras: ftp.tsukuba.wide.ad.jp
* updates: ftp.tsukuba.wide.ad.jp
epel/pkgtags | 325 B 00:00
==================================================================== N/S Matched: ncftp =====================================================================
ncftp.i686 : Improved console FTP client
Name and summary matches only, use "search all" for everything.
[root@192 duplicity-0.6.20]# yum install ncftp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tsukuba.wide.ad.jp
* epel: ftp.tsukuba.wide.ad.jp
* extras: ftp.tsukuba.wide.ad.jp
* updates: ftp.tsukuba.wide.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ncftp.i686 2:3.2.4-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Installing:
ncftp i686 2:3.2.4-1.el6 epel 315 k
Transaction Summary
=============================================================================================================================================================
Install 1 Package(s)
Total download size: 315 k
Installed size: 1.3 M
Is this ok [y/N]: y
Downloading Packages:
ncftp-3.2.4-1.el6.i686.rpm | 315 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 2:ncftp-3.2.4-1.el6.i686 1/1
Verifying : 2:ncftp-3.2.4-1.el6.i686 1/1
Installed:
ncftp.i686 2:3.2.4-1.el6
Complete!
■ncftpのバージョンを見てみる
# ncftp --version
NcFTP 3.2.4 (Apr 07, 2010) by Mike Gleason (http://www.NcFTP.com/contact/).
ここまででインストールは完了。
■ローカル内でのバックアップ例
○作業場所例
$ pwd
/home/user
○バックアップ元
$ ls -al ./work/
合計 12
drwxrwxr-x 2 user user 4096 12月 21 20:29 2012 ./
drwxrwxrwx. 14 user user 4096 12月 21 20:32 2012 ../
-rw-rw-r-- 1 user user 11 12月 21 20:29 2012 first.txt
○バックアップ先
$ ls -al dup_backup_test/
合計 8
drwxrwxr-x 2 user user 4096 12月 21 20:33 2012 ./
drwxrwxrwx. 14 user user 4096 12月 21 20:32 2012 ../
○初回フルバックアップ
$ duplicity ./work file:///home/user/dup_backup_test
Import of duplicity.backends.u1backend Failed: No module named httplib2
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: none
GnuPG passphrase:
Retype passphrase to confirm:
No signatures found, switching to full backup.
--------------[ Backup Statistics ]--------------
StartTime 1356089561.48 (Fri Dec 21 20:32:41 2012)
EndTime 1356089561.49 (Fri Dec 21 20:32:41 2012)
ElapsedTime 0.01 (0.01 seconds)
SourceFiles 2
SourceFileSize 4107 (4.01 KB)
NewFiles 2
NewFileSize 4107 (4.01 KB)
DeletedFiles 0
ChangedFiles 0
ChangedFileSize 0 (0 bytes)
ChangedDeltaSize 0 (0 bytes)
DeltaEntries 2
RawDeltaSize 11 (11 bytes)
TotalDestinationSizeChange 234 (234 bytes)
Errors 0
-------------------------------------------------
○初回バックアップ後のバックアップ先
$ ls -al ./dup_backup_test/
合計 20
drwxrwxr-x 2 user user 4096 12月 21 20:36 2012 ./
drwxrwxrwx. 14 user user 4096 12月 21 20:32 2012 ../
-rw------- 1 user user 261 12月 21 20:36 2012 duplicity-full-signatures.20121221T113556Z.sigtar.gpg
-rw------- 1 user user 196 12月 21 20:36 2012 duplicity-full.20121221T113556Z.manifest.gpg
-rw------- 1 user user 234 12月 21 20:36 2012 duplicity-full.20121221T113556Z.vol1.difftar.gpg
○バックアップ元を変更する
$ ls -al ./work/
合計 16
drwxrwxr-x 2 user user 4096 12月 21 20:37 2012 ./
drwxrwxrwx. 14 user user 4096 12月 21 20:37 2012 ../
-rw-rw-r-- 1 user user 11 12月 21 20:29 2012 first.txt
-rw-rw-r-- 1 user user 12 12月 21 20:37 2012 second.txt
○2回目のバックアップ
$ duplicity ./work file:///home/user/dup_backup_test
Import of duplicity.backends.u1backend Failed: No module named httplib2
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: Fri Dec 21 20:35:56 2012
GnuPG passphrase:
Retype passphrase to confirm:
--------------[ Backup Statistics ]--------------
StartTime 1356089881.33 (Fri Dec 21 20:38:01 2012)
EndTime 1356089881.34 (Fri Dec 21 20:38:01 2012)
ElapsedTime 0.01 (0.01 seconds)
SourceFiles 3
SourceFileSize 4119 (4.02 KB)
NewFiles 2
NewFileSize 4108 (4.01 KB)
DeletedFiles 0
ChangedFiles 0
ChangedFileSize 0 (0 bytes)
ChangedDeltaSize 0 (0 bytes)
DeltaEntries 2
RawDeltaSize 12 (12 bytes)
TotalDestinationSizeChange 233 (233 bytes)
Errors 0
-------------------------------------------------
○2回目バックアップ後のバックアップ先
$ ls -al ./dup_backup_test/
合計 32
drwxrwxr-x 2 user user 4096 12月 21 20:38 2012 ./
drwxrwxrwx. 14 user user 4096 12月 21 20:37 2012 ../
-rw------- 1 user user 261 12月 21 20:36 2012 duplicity-full-signatures.20121221T113556Z.sigtar.gpg
-rw------- 1 user user 196 12月 21 20:36 2012 duplicity-full.20121221T113556Z.manifest.gpg
-rw------- 1 user user 234 12月 21 20:36 2012 duplicity-full.20121221T113556Z.vol1.difftar.gpg
-rw------- 1 user user 196 12月 21 20:38 2012 duplicity-inc.20121221T113556Z.to.20121221T113757Z.manifest.gpg
-rw------- 1 user user 233 12月 21 20:38 2012 duplicity-inc.20121221T113556Z.to.20121221T113757Z.vol1.difftar.gpg
-rw------- 1 user user 263 12月 21 20:38 2012 duplicity-new-signatures.20121221T113556Z.to.20121221T113757Z.sigtar.gpg
○バックアップ状態の確認
$ duplicity collection-status file:///home/user/dup_backup_test
Import of duplicity.backends.u1backend Failed: No module named httplib2
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: Fri Dec 21 20:35:56 2012
Collection Status
-----------------
Connecting with backend: LocalBackend
Archive dir: /home/user/.cache/duplicity/8716bfe8333e4b5eaeabee4eec99bcbf
Found 0 secondary backup chains.
Found primary backup chain with matching signature chain:
-------------------------
Chain start time: Fri Dec 21 20:35:56 2012
Chain end time: Fri Dec 21 20:37:57 2012
Number of contained backup sets: 2
Total number of contained volumes: 2
Type of backup set: Time: Num volumes:
Full Fri Dec 21 20:35:56 2012 1
Incremental Fri Dec 21 20:37:57 2012 1
-------------------------
No orphaned or incomplete backup sets found.
■レストアしてみる
workの下を空にしておく
$ ls -al ./work/
合計 8
drwxrwxr-x 2 user user 4096 12月 21 20:42 2012 ./
drwxrwxrwx. 14 user user 4096 12月 21 20:37 2012 ../
レストアする
$ duplicity file:///home/user/dup_backup_test /home/user/work
Import of duplicity.backends.u1backend Failed: No module named httplib2
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: Fri Dec 21 20:35:56 2012
GnuPG passphrase:
$ ls -al ./work/
合計 16
drwxrwxr-x 2 user user 4096 12月 21 20:37 2012 ./
drwxrwxrwx. 14 user user 4096 12月 21 20:37 2012 ../
-rw-rw-r-- 1 user user 11 12月 21 20:29 2012 first.txt
-rw-rw-r-- 1 user user 12 12月 21 20:37 2012 second.txt
復元する日時を指定した場合は–restore-time(-t)をオプションとして日時を指定して実行する。
特定のディレクトリだけ復元したい場合は–file-to-restoreオプションでパス名を指定する。
すでにあるディレクトリに上書きする形で復元したいときは–forceオプションをつける
■GnuPGでパスフレーズを毎回求められるのが面倒な場合
事前にexportしておくと楽かも。
export PASSPHRASE=gpgpassphrase
■古いバックアップの削除
5組のバックアップを残してそれ以前のものを削除する場合
$ duplicity remove-all-but-n-full 5 /home/user/dup_backup_test
ある日以前のバックアップを削除する場合
$ duplicity remove-older-than 3M /home/user/dup_backup_test
■年月日の指定方法
○年月日と時間の指定(日本時間の2008年9月4日 18:57:11)
2008-09-04T18:57:11+09:00
○年月日の指定(2008年9月4日)
2008-09-04
2008/09/04
09/04/2008
09-04-2008
○相対的な指定
3D5h45m(3日前と5時間45分前)
5Y4M15s(5年4ヶ月と15秒前)
○現在
now
■duplicityがサポートするアクセス方法と対応するURLのフォーマット
cf+http://container_name |
file:///some_dir |
ftp://user[:password]@other.host[:port]/some_dir |
ftps://user[:password]@other.host[:port]/some_dir |
hsi://user[:password]@other.host[:port]/some_dir |
imap://user[:password]@other.host[:port]/some_dir |
rsync://user[:password]@other.host[:port]::/module/some_dir |
rsync://user[:password]@other.host[:port]/relative_path |
rsync://user[:password]@other.host[:port]//absolute_path |
s3://other.host/bucket_name[/prefix] |
s3+http://bucket_name[/prefix] |
scp://user[:password]@other.host[:port]/some_dir |
ssh://user[:password]@other.host[:port]/some_dir |
tahoe://alias/directory |
webdav://user[:password]@other.host/some_dir |
webdavs://user[:password]@other.host/some_dir |
gdocs://user[:password]@other.host/some_dir |
■その他
使い方:
duplicity [full|incremental] [options] source_dir target_url
duplicity [restore] [options] source_url target_dir
duplicity verify [options] source_url target_dir
duplicity collection-status [options] target_url
duplicity list-current-files [options] target_url
duplicity cleanup [options] target_url
duplicity remove-older-than time [options] target_url
duplicity remove-all-but-n-full count [options] target_url
duplicity remove-all-inc-of-but-n-full count [options] target_url
コマンド:
cleanup
collection-status
full
incr
list-current-files
restore
remove-older-than <time>
remove-all-but-n-full
remove-all-inc-of-but-n-full
verify
オプション:
-h, --help show this help message and exit
--allow-source-mismatch
--archive-dir=path
--asynchronous-upload
--dry-run
--encrypt-key=gpg-key-id
--encrypt-secret-keyring=path
--encrypt-sign-key=gpg-key-id
--exclude=shell_pattern
--exclude-device-files
--exclude-filelist=filename
--exclude-filelist-stdin
--exclude-globbing-filelist=filename
--exclude-if-present=filename
--exclude-other-filesystems
--exclude-regexp=regular_expression
--extra-clean
--file-prefix=FILE_PREFIX
-r path, --file-to-restore=path
--force
--ftp-passive
--ftp-regular
--full-if-older-than=time
--gio
--gpg-options=options
--ignore-errors
--imap-mailbox=imap_mailbox
--include=shell_pattern
--include-filelist=filename
--include-filelist-stdin
--include-globbing-filelist=filename
--include-regexp=regular_expression
--log-fd=file_descriptor
--log-file=filename
--name=backup name
--no-encryption
--no-compression
--no-print-statistics
--null-separator
--num-retries=number
--numeric-owner
--old-filenames
--pydevd
--rename=RENAME
-t time, --restore-time=time, --time=time
--rsync-options=options
--s3-european-buckets
--s3-use-rrs
--s3-use-new-style
--s3-unencrypted-connection
--s3-multipart-chunk-size=number
--s3-use-multiprocessing
--scp-command=command
--sftp-command=command
--short-filenames
--sign-key=gpg-key-id
--ssh-askpass
--ssh-backend=paramiko|pexpect
--ssh-options=options
--tempdir=path
--timeout=seconds
--time-separator=char
--use-agent
--use-scp
-v [0-9], --verbosity=[0-9]
-V, --version
--volsize=number
■参考URL
duplicity本家
[CentOS] How to install Duplicity on your VPS/Dedicated Server
Duplicity – secure incremental backup