バイナリーとテキストのデーターを Debian システム上で管理するツールとティップを記します。
![]() |
警告 |
---|---|
競合状態とならないようにするために、アクティブにアクセスされているデバイスやファイルに複数プロセスから調整なく書き込みアクセスをしてはいけません。 |
データーのセキュリティーとそのコントロールされた共有はいくつかの側面があります。
データーアーカイブの作成
遠隔ストレージアクセス
複製
変更履歴の追跡
データー共有のアシスト
不正なファイルへのアクセスの防止
不正なファイルの改変の検出
こういったことは次の組み合わせを使うことで実現できます。
アーカイブと圧縮ツール
コピーと同期ツール
ネットワークファイルシステム
リムーバブルストレージメディア
セキュアーシェル
認証システム
バージョンコントロールシステムツール
ハッシュや暗号学的暗号化ツール
Debian システム上で利用可能なアーカイブと圧縮ツールのまとめを以下に記します。
表10.1 アーカイブと圧縮ツールのリスト
パッケージ | ポプコン | サイズ | 拡張子 | コマンド | コメント |
---|---|---|---|---|---|
tar
|
V:920, I:999 | 3144 | .tar |
tar (1) |
標準アーカイバー (デファクト標準) |
cpio
|
V:416, I:998 | 1141 | .cpio |
cpio (1) |
Unix System V スタイルのアーカイバー、find (1) とともに使用 |
binutils
|
V:160, I:642 | 109 | .ar |
ar (1) |
静的ライブラリー生成用のアーカイバー |
fastjar
|
V:1, I:19 | 183 | .jar |
fastjar (1) |
Java 用のアーカイバー (zip 類似) |
pax
|
V:10, I:18 | 170 | .pax |
pax (1) |
新規 POSIX 標準アーカイバー、tar と cpio の間の妥協点 |
gzip
|
V:882, I:999 | 252 | .gz |
gzip (1), zcat (1), … |
GNU LZ77 圧縮ユーティリティー (デファクト標準) |
bzip2
|
V:161, I:970 | 121 | .bz2 |
bzip2 (1), bzcat (1), … |
gzip (1) より高い圧縮比 (gzip より遅い、類似シンタックス) の
Burrows-Wheeler
ブロック並び替え圧縮ユーティリティー |
lzma
|
V:1, I:20 | 149 | .lzma |
lzma (1) |
LZMA compression utility with higher compression
ratio than gzip (1) (deprecated) |
xz-utils
|
V:432, I:979 | 1216 | .xz |
xz (1), xzdec (1), … |
bzip2 (1) より高い圧縮比の XZ 圧縮ユーティリティー
(gzip より遅いが bzip2 より早い、LZMA 圧縮ユーティリティーの代替) |
zstd
|
V:34, I:91 | 2027 | .zstd |
zstd (1), zstdcat (1), … |
Zstandard fast lossless compression utility |
p7zip
|
V:111, I:454 | 987 | .7z |
7zr (1), p7zip (1) |
高い圧縮比をもつ 7-Zip 圧縮ユーティリティー (LZMA 圧縮) |
p7zip-full
|
V:116, I:460 | 4664 | .7z |
7z (1), 7za (1) |
高い圧縮比をもつ 7-Zip 圧縮ユーティリティー (LZMA 圧縮、他) |
lzop
|
V:13, I:133 | 164 | .lzo |
lzop (1) |
gzip (1) より高い圧縮と解凍の速度 (gzip
より低い圧縮比、類似シンタックス) の LZO 圧縮ユーティリティー |
zip
|
V:47, I:398 | 623 | .zip |
zip (1) |
InfoZIP: DOS アーカイブと圧縮ツール |
unzip
|
V:100, I:772 | 385 | .zip |
unzip (1) |
InfoZIP: DOS アーカイブ解凍と圧縮解凍ツール |
![]() |
警告 |
---|---|
何が起こるかを理解せずに " |
gzip 圧縮された tar
(1) アーカイブは ".tgz
" とか
".tar.gz
" といったファイル拡張子を使います。
xz 圧縮された tar
(1) アーカイブは ".txz
" とか
".tar.xz
" といったファイル拡張子を使います。
tar
(1) 等の FOSS
ツールでのポピュラーな圧縮方法は次のように変遷しています: gzip
→
bzip2
→ xz
cp
(1) と scp
(1) と
tar
(1)
は特殊ファイルに関して一部制約があるかもしれません。cpio
(1) は最も汎用性があります。
cpio
(1) はfind
(1)
等のコマンドとともに使うようにできていて、ファイルの選定部分のスクリプトを独立にテストできるのでバックアップスクリプトを作るのに向いています。
Libreoffice データーファイルの内部構造は ".jar
"
ファイルで、unzip
で開くことができます。
デファクトのクロスプラットフォームのアーカイブツールは zip
です。最大限のコンパチビリティーのためには
"zip -rX
" として使ってください。もし最大ファイルサイズが問題となる際には
"-s
" オプションも使ってください。
Debian システム上で利用可能な単純なコピーとバックアップツールのまとめを以下に記します。
表10.2 コピーと同期ツールのリスト
パッケージ | ポプコン | サイズ | ツール | 機能 |
---|---|---|---|---|
coreutils
|
V:908, I:999 | 18062 | GNU cp | ファイルやディレクトリーのローカルコピー ("-a" で再帰的実行) |
openssh-client
|
V:856, I:997 | 5609 | scp | ファイルやディレクトリーのリモートコピー (クライアント、"-r " で再帰実行) |
openssh-server
|
V:740, I:841 | 1867 | sshd | ファイルやディレクトリーのリモートコピー (リモートサーバー) |
rsync
|
V:285, I:567 | 776 | 単方向リモート同期とバックアップ | |
unison
|
V:3, I:15 | 14 | 双方向リモート同期とバックアップ |
rsync
(8) を使ってのファイルのコピーには他の方法より豊かな機能があります。
転送元のファイルと転送先の既存ファイル間の相違のみを送信する差分転送アルゴリズム
サイズか最終変更時間に変更があったファイルのみを探す (デフォルトで採用される) 急速確認アルゴリズム
tar
(1) 類似の "--exclude
" や
"--exclude-from
" オプション
転送先に追加ディレクトリーレベルを作成しなくする「転送元ディレクトリ後スラシュ (/) 付加」文法
![]() |
ヒント |
---|---|
表10.14「List of other version control system tools」に記されたバージョンコントロールシステム (VCS) ツールは多方向のコピーと同期のツールとして機能します。 |
"./source
"
ディレクトリー中の全内容を異なるツールを用いてアーカイブしアーカイブ解凍するいくつかの方法を以下に記します。
GNU tar
(1):
$ tar -cvJf archive.tar.xz ./source $ tar -xvJf archive.tar.xz
この代わりに、次のようにも出来ます。
$ find ./source -xdev -print0 | tar -cvJf archive.tar.xz --null -F -
cpio
(1):
$ find ./source -xdev -print0 | cpio -ov --null > archive.cpio; xz archive.cpio $ zcat archive.cpio.xz | cpio -i
"./source
" ディレクトリー中の全内容を異なるツールを用いてコピーするいくつかの方法を以下に記します。
ローカルコピー: "./source
" ディレクトリー → "/dest
"
ディレクトリー
リモートコピー: ローカルホストの "./source
" ディレクトリー →
"user@host.dom
" ホストの "/dest
" ディレクトリー
rsync
(8):
# cd ./source; rsync -aHAXSv . /dest # cd ./source; rsync -aHAXSv . user@host.dom:/dest
「転送元ディレクトリー後スラシュ付加」文法を上記の代わりに使えます。
# rsync -aHAXSv ./source/ /dest # rsync -aHAXSv ./source/ user@host.dom:/dest
この代わりに、次のようにも出来ます。
# cd ./source; find . -print0 | rsync -aHAXSv0 --files-from=- . /dest # cd ./source; find . -print0 | rsync -aHAXSv0 --files-from=- . user@host.dom:/dest
GNU cp
(1) と openSSH scp
(1):
# cd ./source; cp -a . /dest # cd ./source; scp -pr . user@host.dom:/dest
GNU tar
(1):
# (cd ./source && tar cf - . ) | (cd /dest && tar xvfp - ) # (cd ./source && tar cf - . ) | ssh user@host.dom '(cd /dest && tar xvfp - )'
cpio
(1):
# cd ./source; find . -print0 | cpio -pvdm --null --sparse /dest
".
" を含むすべての例で ".
"
は"foo
" で代替でき、ファイルを "./source/foo
"
ディレクトリーから "/dest/foo
" ディレクトリにコピーできます。
".
" を含むすべての例で ".
" を絶対パスの
"/path/to/source/foo
" で代替でき、"cd
./source;
" を削除することができます。これらは使うツール次第で異なる場所にファイルをコピーします。
"/dest/foo
": rsync
(8)、GNU
cp
(1)、scp
(1)
"/dest/path/to/source/foo
": GNU tar
(1)
と cpio
(1)
![]() |
ヒント |
---|---|
|
アーカイブやコピーコマンド (「アーカイブの慣用句」と「コピーの慣用句」参照下さい) のためや xargs
(1)
(「ファイルに関してループしながらコマンドを反復実行」参照下さい)
のためにファイルを選択するのに find
(1) が使われます。これの操作は
find
(1) のコマンド引数を使うことで強化できます。
find
(1) の基本シンタックスは次のようにまとめられます。
条件の引数は左から右へと評価されます。
結果が決まった時点で評価は終了します。
"論理 OR" (条件間に "-o
"
で指定) は、"論理 AND" (条件間に
"-a
" または何もなしで指定) より低い優先順位です。
"論理 NOT" (条件前に "!
"
で指定) は、"論理 AND" より高い優先順位です。
"-prune
" は常に論理真 (TRUE)
を返し、ディレクトリーの場合にはこの点以降のファイル探索を停止します。
"-name
" はシェルのグロブ (「シェルグロブ」参照下さい)
を使ってファイル名のベースにマッチし、さらに "*
" and "?
"
等のメタ文字で最初の ".
" ともマッチします。(新規の POSIX 機能)
"-regex
" はデフォールトでは emacs スタイルの BRE (「正規表現」参照下さい)
を用いてフルパスをマッチします。
"-size
" はファイルサイズ ("+
"
が前に付いた値はより大きい、"-
" が前に付いた値はより小さい) に基づいてファイルをマッチします。
"-newer
" はその引数に指定されたファイルより新しいファイルとマッチします。
"-print0
" は常に論理真
(TRUE) を返し、フルファイル名を (null
終端処理して) 標準出力へプリントします。
find
(1) はしばしば慣用的なスタイルで使われます。
# find /path/to \ -xdev -regextype posix-extended \ -type f -regex ".*\.cpio|.*~" -prune -o \ -type d -regex ".*/\.git" -prune -o \ -type f -size +99M -prune -o \ -type f -newer /path/to/timestamp -print0
これは次のアクションをすることを意味します。
"/path/to
" からはじまる全ファイルを探索
探索開始したファイルシステムに探索を全体的に制約し、デフォールトの代わりに ERE (「正規表現」参照下さい) を使用
正規表現 ".*\.cpio
" か ".*~
"
にマッチするファイルを処理停止をすることで探索から除外
正規表現 ".*/\.git
" にマッチするディレクトリーを処理停止をすることで探索から除外
9MiB(1048576バイトの単位) より大きいファイルを処理停止をすることで探索から除外
上記の探索条件に合致し "/path/to/timestamp
" より新しいファイル名をプリントします
上記例中でファイルを検索から除外するときの "-prune -o
" の慣用的な使い方に注目して下さい。
![]() |
注記 |
---|---|
非 Debian のUnix 的システムでは、一部のオプションは
|
重要なデーターアーカイブのためのコンピューターデーターストレージメディアを選ぶ時にはそれらの限界について注意を払うべきです。小さな個人的なバックアップのためには、著者としては名前が知られている会社の CD-R と DVD-R を使い、クールで日陰の乾燥した埃の無い環境に保存しています。(プロ用途ではテープアーカイブメディアに人気があるようです。)
![]() |
注記 |
---|---|
耐火金庫は紙の文書のためのものです。ほとんどのコンピューターデーターストレージメディアは紙よりも耐熱性がありません。著者は通常複数の安全な場所に保管された複数のセキュアーな暗号化されたコピーに頼っています。 |
ネット上に散見するアーカイブメディアの楽観的なストレージ寿命 (ほとんどベンダー情報由来)。
100+年: インクと中性紙
100年: オプティカルストレージ (CD/DVD、CD/DVD-R)
30年: 磁気ストレージ (テープ、フロッピー)
20年: 相変化オプティカルストレージ (CD-RW)
これらは取扱いによる機械的故障等は考慮していません。
ネット上に散見するアーカイブメディアの楽観的な書込み回数 (ほとんどベンダー情報由来)。
250,000+回: ハードディスク
10,000+回: フラッシュメモリー
1,000回: CD/DVD-RW
1回: CD/DVD-R、紙
![]() |
注意 |
---|---|
ここにあるストレージ寿命や書込み回数の数字はクリチカルなデーターストレージに関する決定に使うべきではありません。製造者によって提供される特定の製品情報を参照下さい。 |
![]() |
ヒント |
---|---|
CD/DVD-R や紙は1回しか書けないので、本質的に重ね書きで間違ってデーターを消すことを防げます。これは、利点です! |
![]() |
ヒント |
---|---|
もし高速で頻繁な大量のデーターのバックアップをする必要がある場合、高速のネットワーク接続でつながっているリモートホスト上のハードディスクが唯一の現実的なオプションかもしれません。 |
リムーバブルストレージデバイスは次の何れも指します。
デジタルカメラ
デジタル音楽プレーヤー
これらは次の何れかで接続できます。
GNOME や KDE のような最近のデスクトップ環境は、"/etc/fstab
"
エントリーにマッチが無いリムーバブルデバイスを自動的にマウントする事ができます。
![]() |
ヒント |
---|---|
自動的にマウントされたデバイスは、 |
![]() |
ヒント |
---|---|
" |
Mount point under modern desktop environment is chosen as
"/media/username/disk_label
" which
can be customized by the following.
FAT ファイルシステムでは、mlabel
(1) を使います。
ISO9660 ファイルシステムでは、genisoimage
(1)
を"-V
" オプションとともに使います。
ext2/ext3/ext4 ファイルシステムでは、tune2fs
(1)
を"-L
" オプションとともに使います。
![]() |
ヒント |
---|---|
符号化方式 (エンコーディング) の選択をマウントオプションとして与える必要があるかもしれません (「ファイル名の符号化方式」参照下さい)。 |
![]() |
ヒント |
---|---|
ファイルシステムをアンマウンとする際に GUI メニューを使うと、動的に生成された " |
リムーバブルストレージデバイスを使ってデーターを共有する際には、両方のシステムにサポートされた共通のファイルシステムでそれをフォーマットするべきです。ファイルシステム選択のリストを次に示します。
表10.3 典型的な使用シナリオに合わせたリムーバブルストレージデバイスのファイルシステムの選択肢のリスト
filesystem name | typical usage scenario |
---|---|
FAT12 | フロッピーディスク上のクロスプラットフォームのデーター共有 (<32MiB) |
FAT16 | 小さなハードディスク類似のデバイス上のクロスプラットフォームのデーター共有 (<2GiB) |
FAT32 | 大きなハードディスク類似のデバイス上のクロスプラットフォームのデーター共有 (<8TiB, MS Windows95 OSR2 以降でサポート有り) |
exFAT | cross platform sharing of data on the large hard disk like device (<512TiB, supported by WindowsXP, Mac OS X Snow Leopard 10.6.5, and Linux kernel since 5.4 release) |
NTFS | 大きなハードディスク類似のデバイス上のクロスプラットフォームのデーター共有 (MS Windows NT 以降でネイティブにサポート、Linux 上では FUSE 経由の NTFS-3G でサポート) |
ISO9660 | CD-R and DVD+/-R 上の静的データーのクロスプラットフォームの共有 |
UDF | CD-R や DVD+/-R 上への増分データーの書込み (新規) |
MINIX | フロッピーディスク上へのスペース効率の良い unix ファイルデーターのストレージ |
ext2 | 古い Linux システムとハードディスク類似デバイス上のデーターを共有 |
ext3 | 古い Linux システムとハードディスク類似デバイス上のデーターを共有 |
ext4 | 最新の Linux システムとハードディスク類似デバイス上のデーターを共有 |
btrfs | sharing of data on the hard disk like device with current Linux systems with read-only snapshots |
![]() |
ヒント |
---|---|
デバイスレベルの暗号化を使ったクロスプラットフォームのデーター共有に関しては、「dm-crypt/LUKS を使ったリムーバブルディスクの暗号化」を参照下さい。 |
FAT ファイルシステムはほとんど全ての現代的なオペレーティングシステムでサポートされていて、ハードディスク類似のメディア経由でのデーター交換目的に非常に有用です。
クロスプラットフォームの FAT ファイルシステムを使ったデーター共有にリムーバブルハードディスク類似デバイスをフォーマットする時の安全な選択肢は次です。
fdisk
(8) か cfdisk
(8) か
parted
(8) (「ディスクパーティション設定」参照下さい)
を使ってそれを単一のプライマリパーティションにパーティションしそれを次のようにマークします。
2GB より小さなメディアには FAT16 となるように "6" とタイプします
大きなメディアには FAT32 (LBA) となるように "c" とタイプします
第1パーティションを mkfs.vfat
(8) を使って次のようにフォーマットします。
FAT16 となるように "/dev/sda1
" 等とそのデバイス名だけを使います
FAT32 となるように "-F 32 /dev/sda1
" 等と明示的なオプション指定とそのデバイス名を使います
FAT とか ISO9660 ファイルシステムを使ってデーターを共有する際の安全への配慮を次に記します。
tar
(1) や cpio
(1)
を使ってアーカイブファイルに最初にファイルをアーカイブすることで長いファイル名やシンボリックリンクやオリジナルの Unix
ファイルパーミッションとオーナー情報を保持します。
split
(1) コマンドを使ってアーカイブファイルを 2GiB
以下の塊に分割してファイルサイズの制約から保護します。
アーカイブファイルを暗号化してその内容を不正アクセスから保護します。
![]() |
注記 |
---|---|
FAT ファイルシステムはその設計上最大ファイルサイズは |
![]() |
注記 |
---|---|
Microsoft 自身も 200MB を越すドライブやパーティションに FAT を使うことを勧めていません。マイクロソフトは、彼らの "Overview of FAT, HPFS, and NTFS File Systems" で非効率的なディスク領域の使用等の欠点をハイライトしています。もちろん私たちは Linux では通常 ext4 ファイルシステムを使うべきです。 |
![]() |
ヒント |
---|---|
ファイルシステムとファイルシステムのアクセスに関しての詳細は、"Filesystems HOWTO" を参照下さい。 |
データーをネットワーク経由で他のシステムと共有するときには、共通のサービスを使うべきです。次に一部のヒントを記します。
表10.4 典型的使用シナリオの場合のネットワークサービスの選択のリスト
ネットワークサービス | 典型的使用シナリオの説明 |
---|---|
Samba を使う SMB/CIFS ネットワーク経由マウントファイルシステム | "Microsoft Windows Network" 経由でのファイル共有、smb.conf (5) と
The Official Samba 3.x.x
HOWTO and Reference Guide か samba-doc パッケージ参照下さい |
Linux カーネルを使う NFS ネットワークマウントファイルシステム | "Unix/Linux Network" 経由のファイル共有、exports (5) と Linux NFS-HOWTO 参照下さい。 |
HTTP サービス | ウェッブサーバー/クライアント間のファイル共有 |
HTTPS サービス | 暗号化されたセキュアーソケットレイヤー (SSL) もしくは Transport Layer Security (TLS) を使ったウェッブサーバー/クライアント間のファイル共有 |
FTP サービス | FTP サーバー/クライアント間のファイル共有 |
このようなネットワーク経由でマウントされたファイルシステムやネットワーク経由のファイル転送法はデーター共有のために非常に便利ですが、インセキュアーかもしれませんこれらのネットワーク接続は次に記すようにしてセキュアーにされなければいけません。
コンピューターはいつか壊れるとか、人間によるエラーがシステムやデーターをへの損害を及ぼすことは皆知っています。バックアップと復元の操作は正しいシステム管理の必須構成要素です。考えうる全ての故障モードはいつかの日にやって来ます。
![]() |
ヒント |
---|---|
バックアップのシステムは簡単にしておき、システムのバックアップは頻繁にします。バックアップデーターが存在することは、あなたのバックアップ方法が技術的に如何に良いかよりも重要です。 |
実際のバックアップと復元の方針を決める上で3つの要素があります。
何をバックアップし復元するかを知っていること
あなた自身が作成したデーターファイル: "~/
" 中のデーター
あなた自身が使用したアプリケーションが作成したデーターファイル: "/var/
"
("/var/cache/
" と "/var/run/
" と
"/var/tmp/
" は除外) 中のデーター
システム設定ファイル: "/etc/
" 中のデーター
Local programs: data in "/usr/local/
" or
"/opt/
"
システムインストール情報: 要点 (パーティション、…) をプレーンテキストで書いたメモ
実証済みのデーターセット: 事前に実験的復元操作をして確認済み
Cron job as a user process: files in
"/var/spool/cron/crontabs
" directory and restart
cron
(8). See 「タスク定期実行のスケジュール」 for cron
(8) and
crontab
(1).
Systemd timer jobs as user processes: files in
"~/.config/systemd/user
" directory. See
systemd.timer
(5) and
systemd.service
(5).
Autostart jobs as user processes: files in
"~/.config/autostart
" directory. See Desktop Application Autostart
Specification.
バックアップと復元の方法を知っていること
セキュアーなデーターのストレージ: 上書きやシステム障害の防止
頻繁なバックアップ: スケジュールされたバックアップ
冗長なバックアップ: データーのミラーリング
フルプルーフなプロセス: 簡単な単一コマンドバックアップ
関わっているリスクと費用の評価
Risk of data when lost
Data should be at least on different disk partitions preferably on different disks and machines to withstand the filesystem corruption. Important data are best stored on a read-only filesystem. [4]
Risk of data when breached
Sensitive identity data such as
"/etc/ssh/ssh_host_*_key
",
"~/.gnupg/*
", "~/.ssh/*
",
"~/.local/share/keyrings/*
",
"/etc/passwd
", "/etc/shadow
",
"popularity-contest.conf
",
"/etc/ppp/pap-secrets
", and
"/etc/exim4/passwd.client
" should be backed up as
encrypted. [5] (See 「データー暗号化ティップ」.)
Never hard code system login password nor decryption passphrase in any script even on any trusted system. (See 「Password keyring」.)
故障モードとその確率
Hardware (especially HDD) will break
Filesystem may be corrupted and data in it may be lost
Remote storage system can't be trusted for security breaches
Weak password protection can be easily compromised
File permission system may be compromised
バックアップに必要なリソース: 人的、ハードウエアー、ソフトウエアー、…
Automatic scheduled backup with cron job or systemd timer job
![]() |
注記 |
---|---|
|
![]() |
注記 |
---|---|
データーをバックアップする際には MTA (「メール転送エージェント (MTA)」参照下さい) 等のアプリケーションデーモンを停止するのも一計です。 |
Debian システム上で利用可能でバックアップユーティリティーのスイートのなかで際立った選ばれたリストを記します。
表10.5 バックアップスイートのユーティリティーのリスト
パッケージ | ポプコン | サイズ | 説明 |
---|---|---|---|
dump
|
V:1, I:5 | 351 | ext2/ext3/ext4 ファイルシステム用の 4.4 BSD 由来の
dump (8) と restore (8) |
xfsdump
|
V:0, I:8 | 848 | GNU/Linux と IRIX 上の XFS ファイルシステム用の xfsdump (8) と
xfsrestore (8) を使う dump と restore |
backupninja
|
V:3, I:4 | 367 | 軽量で拡張可のメタバックアップシステム |
bacula-common
|
V:10, I:12 | 2120 | Bacula: ネットワークバックアップ、復元および検証 - 共通のサポートファイル |
bacula-client
|
I:3 | 183 | Bacula: ネットワークバックアップ、復元および検証 - クライアントメタパッケージ |
bacula-console
|
V:0, I:4 | 104 | Bacula: ネットワークバックアップ、復元および検証 - テキストコンソール |
bacula-server
|
I:1 | 183 | Bacula: ネットワークバックアップ、復元および検証 - サーバーメタパッケージ |
amanda-common
|
V:0, I:2 | 9937 | Amanda: Advanced Maryland Automatic Network Disk Archiver (ライブラリー) |
amanda-client
|
V:0, I:2 | 1085 | Amanda: Advanced Maryland Automatic Network Disk Archiver (クライアント) |
amanda-server
|
V:0, I:0 | 1077 | Amanda: Advanced Maryland Automatic Network Disk Archiver (サーバー) |
backup-manager
|
V:0, I:1 | 571 | コマンドラインのバックアップツール |
backup2l
|
V:0, I:0 | 115 | マウントできるメディアのための低メンテナンスのバックアップ/復旧ツール (ディスクベース) |
backuppc
|
V:2, I:2 | 3178 | BackupPC は高性能でエンタープライズ級の、PC をバックアップするためのシステム (ディスクベース) |
duplicity
|
V:19, I:40 | 1859 | (リモート) 増分バックアップ |
flexbackup
|
V:0, I:0 | 243 | (リモート) 増分バックアップ |
rdiff-backup
|
V:5, I:12 | 1162 | (リモート) 増分バックアップ |
restic
|
V:2, I:5 | 21593 | (リモート) 増分バックアップ |
slbackup
|
V:0, I:0 | 151 | (リモート) 増分バックアップ |
バックアップツールにはそれぞれの特別な狙いがあります。
Mondo Rescue を使うと、通常のインストールプロセスを経ずにバックアップ CD/DVD 等から完全なシステムを迅速に復旧できます。
Bacula と Amanda と BackupPC は、ネットワーク越しの定期的バックアップに焦点のあるフル機能のバックアップスイートです。
Regular backups of user data can be realized by a simple script (「Personal backup」).
「アーカイブと圧縮ツール」や「コピーと同期ツール」に記された基本的なツールを使うとカスタムスクリプト経由のシステムバックアップができます。そのようなスクリプトは次を使うと強化できます。
restic
パッケージは差分(遠隔)バックアップを提供します。
rdiff-backup
パッケージは (リモートの) 増分バックアップを可能にします。
dump
パッケージは全ファイルシステムの効率的かつ増分のバックアップと復旧を補助します。
![]() |
ヒント |
---|---|
|
For a personal Debian desktop system running testing
suite, I only need to protect personal and critical data. I reinstall
system once a year anyway. Thus I see no reason to backup the whole system
or to install a full featured backup utility.
At the same time, it is very valuable to have frequent recent snapshots of personal data and system configuration, and occasional full backups of personal data.
I usually make these snapshots and backups with a simple shell script bss. This script is a short shell which uses standard
utilities: btrfs subvolume snapshot
,
rsync
. For data encryption, disk image is created by
fallocate
(1) and configured with
cryptsetup
(8).
![]() |
ヒント |
---|---|
debconf の設定データーは " |
データーのセキュリティーのインフラはデーターの暗号化のツールとメッセージダイジェストのツールと署名ツールの組み合わせで提供されます。
表10.6 データーセキュリティーインフラツールのリスト
パッケージ | ポプコン | サイズ | コマンド | 説明 |
---|---|---|---|---|
gnupg
|
V:551, I:918 | 885 | gpg (1) |
GNU プライバシーガード - OpenPGP 暗号化ト署名ツール |
gpgv
|
V:897, I:999 | 917 | gpgv (1) |
GNU プライバシガード - 署名確認ツール |
paperkey
|
V:1, I:13 | 58 | paperkey (1) |
OpenPGP の秘密キーから秘密の情報だけを抜粋 |
cryptsetup
|
V:30, I:77 | 406 | cryptsetup (8), … |
utilities for dm-crypt block device encryption supporting LUKS |
coreutils
|
V:908, I:999 | 18062 | md5sum (1) |
MD5 メッセージダイジェストを計算やチェック |
coreutils
|
V:908, I:999 | 18062 | sha1sum (1) |
SHA1 メッセージダイジェストを計算やチェック |
openssl
|
V:841, I:995 | 2269 | openssl (1ssl) |
"openssl dgst " を使ってメッセージダイジェストを計算やチェック (OpenSSL) |
libsecret-tools
|
V:1, I:12 | 44 | secret-tool (1) |
store and retrieve passwords (CLI) |
seahorse
|
V:72, I:248 | 7987 | seahorse (1) |
key management tool (GNOME) |
See 「データー暗号化ティップ」 on dm-crypt and fscrypt which implement automatic data encryption infrastructure via Linux kernel modules.
基本的なキー管理に関する GNU プライバシガードコマンドを次に記します。
表10.7 キー管理のための GNU プライバシガードコマンドのリスト
コマンド | 説明 |
---|---|
gpg --gen-key |
新規キーの生成 |
gpg --gen-revoke my_user_ID |
my_user_ID に関するリボークキーを生成 |
gpg --edit-key user_ID |
インタラクティブにキーを編集、ヘルプは "help" |
gpg -o file --export |
全てのキーをファイルにエクスポート |
gpg --import file |
全てのキーをファイルからインポート |
gpg --send-keys user_ID |
user_ID のキーをキーサーバーに送信 |
gpg --recv-keys user_ID |
user_ID のキーをキーサーバーから受信 |
gpg --list-keys user_ID |
user_ID のキーをリスト |
gpg --list-sigs user_ID |
user_ID の署名をリスト |
gpg --check-sigs user_ID |
user_ID の署名をチェック |
gpg --fingerprint user_ID |
user_ID のフィンガープリントをチェック |
gpg --refresh-keys |
ローカルキーリングをアップデート |
トラストコードの意味を次に記します。
表10.8 トラストコードの意味のリスト
コード | 信用の説明 |
---|---|
- |
所有者への信用未付与/未計算 |
e |
信用計算に失敗 |
q |
計算用の情報不十分 |
n |
このキーを信用不可 |
m |
スレスレの信用 |
f |
フルに信用 |
u |
究極の信用 |
次のようにすると私のキー "1DD8D791
" をポピュラーなキーサーバー
"hkp://keys.gnupg.net
" にアップロード出来ます。
$ gpg --keyserver hkp://keys.gnupg.net --send-keys 1DD8D791
"~/.gnupg/gpg.conf
" (もしくは古い場所
"~/.gnupg/options
") 中の良いデフォールトのキーサーバーの設定は次を含みます。
keyserver hkp://keys.gnupg.net
次によってキーサーバーから知らないキーが獲得できます。
$ gpg --list-sigs --with-colons | grep '^sig.*\[User ID not found\]' |\ cut -d ':' -f 5| sort | uniq | xargs gpg --recv-keys
OpenPGP 公開キーサーバー
(バージョン0.9.6以前) に2つ以上サブキーのあるキーを壊すバグがありました。新しい gnupg
(>1.2.1-2) パッケージはこのような壊れたサブキーを取り扱えます。gpg
(1)
の"--repair-pks-subkey-bug
" オプションの説明を参照下さい。
基本的なキー管理に関する GNU プライバシガードコマンドを次に記します。
表10.9 ファイルに使用する GNU プライバシーガードコマンドのリスト
コマンド | 説明 |
---|---|
gpg -a -s file |
ファイルを ASCII 文字化した file.asc と署名 |
gpg --armor --sign file |
, , |
gpg --clearsign file |
メッセージをクリアサイン |
gpg --clearsign file|mail foo@example.org |
foo@example.org にクリアサインされたメッセージをメールする |
gpg --clearsign --not-dash-escaped patchfile |
パッチファイルをクリアサイン |
gpg --verify file |
クリアサインされたファイルを確認 |
gpg -o file.sig -b file |
署名を別ファイルで作成 |
gpg -o file.sig --detach-sig file |
, , |
gpg --verify file.sig file |
file.sig を使ってファイルを確認 |
gpg -o crypt_file.gpg -r name -e file |
file からバイナリー crypt_file.gpg への name 宛公開キー暗号化 |
gpg -o crypt_file.gpg --recipient name --encrypt file |
, , |
gpg -o crypt_file.asc -a -r name -e file |
file から ASCII 文字化された crypt_file.asc への name 宛公開キー暗号化 |
gpg -o crypt_file.gpg -c file |
file からバイナリー crypt_file.gpg への対称暗号化 |
gpg -o crypt_file.gpg --symmetric file |
, , |
gpg -o crypt_file.asc -a -c file |
file から ASCII 文字化された crypt_file.asc への対称暗号化 |
gpg -o file -d crypt_file.gpg -r name |
暗号解読 |
gpg -o file --decrypt crypt_file.gpg |
, , |
インデックスメニュー上で "S
" とすれば GnuPG が使えるようにしておきながら、遅い GnuPG
が自動的に起動しないように "~/.muttrc
" に次の内容を追加します。
macro index S ":toggle pgp_verify_sig\n" set pgp_verify_sig=no
The gnupg
plugin let you run GnuPG transparently for
files with extension ".gpg
", ".asc
",
and ".ppg
".[6]
$ sudo aptitude install vim-scripts $ echo "packadd! gnupg" >> ~/.vim/vimrc
md5sum
(1) はrfc1321
の方法を使ってダイジェストファイルを作成し各ファイルをそれで確認するユーティリティーを提供します。
$ md5sum foo bar >baz.md5 $ cat baz.md5 d3b07384d113edec49eaa6238ad5ff00 foo c157a79031e1c40f85931829bc5fc552 bar $ md5sum -c baz.md5 foo: OK bar: OK
![]() |
注記 |
---|---|
MD5 和の計算は GNU プライバシーガード (GnuPG) による暗号学的署名の計算より CPU への負荷がかかりません。通常、一番上のレベルのダイジェストファイルだけがデーターの整合性のために暗号学的に署名されます。 |
On GNOME system, the GUI tool seahorse
(1) manages
passwords and stores them securely in the keyring
~/.local/share/keyrings/*
.
secret-tool
(1) can store password to the keyring from the
command line.
Let's store passphrase used for LUKS/dm-crypt encrypted disk image
$ secret-tool store --label='LUKS passphrase for disk.img' LUKS my_disk.img Password: ********
This stored password can be retrieved and fed to other programs, e.g.,
cryptsetup
(8).
$ secret-tool lookup LUKS my_disk.img | \ cryptsetup open disk.img disk_img --type luks --keyring - $ sudo mount /dev/mapper/disk_img /mnt
![]() |
ヒント |
---|---|
Whenever you need to provide password in a script, use
|
ソースコードをマージする多くのツールがあります。次のコマンドが著者の目に止まりました。
表10.10 ソースコードマージツールのリスト
パッケージ | ポプコン | サイズ | コマンド | 説明 |
---|---|---|---|---|
patch
|
V:90, I:702 | 248 | patch (1) |
差分ファイルをオリジナルに適用 |
vim
|
V:97, I:390 | 3570 | vimdiff (1) |
vim で2つのファイルを並べて比較 |
imediff
|
V:0, I:0 | 169 | imediff (1) |
対話型フルスクリーンの2方/3方マージツール |
meld
|
V:11, I:34 | 3500 | meld (1) |
ファイルを比較やマージ (GTK) |
wiggle
|
V:0, I:0 | 174 | wiggle (1) |
リジェクトされたパッチを適用 |
diffutils
|
V:876, I:995 | 1597 | diff (1) |
1行ごとにファイルを比較 |
diffutils
|
V:876, I:995 | 1597 | diff3 (1) |
1行ごとにファイルを比較やマージ |
quilt
|
V:3, I:26 | 773 | quilt (1) |
パッチのシリーズを管理 |
wdiff
|
V:8, I:59 | 648 | wdiff (1) |
テキストファイル間のワードの相違表示 |
diffstat
|
V:12, I:127 | 74 | diffstat (1) |
差分ファイルによる変化のヒストグラム作成 |
patchutils
|
V:14, I:125 | 232 | combinediff (1) |
2つの積み重ねパッチから1つの合計パッチを生成 |
patchutils
|
V:14, I:125 | 232 | dehtmldiff (1) |
HTML ページから差分ファイルを抽出 |
patchutils
|
V:14, I:125 | 232 | filterdiff (1) |
差分ファイルから差分ファイルを抽出や削除 |
patchutils
|
V:14, I:125 | 232 | fixcvsdiff (1) |
CVS により作成された patch (1) が誤解する差分ファイルを修正 |
patchutils
|
V:14, I:125 | 232 | flipdiff (1) |
古い2つのパッチを交換 |
patchutils
|
V:14, I:125 | 232 | grepdiff (1) |
正規表現にマッチするパッチによって変更されるファイルを表示 |
patchutils
|
V:14, I:125 | 232 | interdiff (1) |
2つのユニファイド差分ファイル間の違いを表示 |
patchutils
|
V:14, I:125 | 232 | lsdiff (1) |
どのファイルがパッチによって変更されるかを表示 |
patchutils
|
V:14, I:125 | 232 | recountdiff (1) |
ユニファイドコンテキスト差分ファイルのカウントやオフセットを再計算 |
patchutils
|
V:14, I:125 | 232 | rediff (1) |
手編集された差分ファイルのカウントやオフセットを再計算 |
patchutils
|
V:14, I:125 | 232 | splitdiff (1) |
増分パッチの分離 |
patchutils
|
V:14, I:125 | 232 | unwrapdiff (1) |
ワードラップされたパッチを復元 |
dirdiff
|
V:0, I:2 | 167 | dirdiff (1) |
ディレクトリーツリー間で相違点の表示と変更のマージ |
docdiff
|
V:0, I:0 | 553 | docdiff (1) |
2つのファイルをワード毎/文字毎に比較 |
makepatch
|
V:0, I:0 | 100 | makepatch (1) |
拡張パッチファイルの生成 |
makepatch
|
V:0, I:0 | 100 | applypatch (1) |
拡張パッチファイルの適用 |
ふたつのソースファイル間の相違を抽出したユニファイド差分ファイル は、以下の要領でファイル位置に対応し
"file.patch0
" か "file.patch1
"
として作成されます。
$ diff -u file.old file.new > file.patch0 $ diff -u old/file new/file > file.patch1
差分ファイル (別名、パッチファイル) はプログラム更新を送るのに使われます。受け取った側はこの更新を別のファイルに次のようにして適用します。
$ patch -p0 file < file.patch0 $ patch -p1 file < file.patch1
If you have two versions of a source code, you can perform 2-way merge
interactively using imediff
(1) by the following.
$ imediff -o file.merged file.old file.new
If you have three versions of a source code, you can perform 3-way merge
interactively using imediff
(1) by the following.
$ imediff -o file.merged file.yours file.base file.theirs
Git is the tool of choice these days for the version control system (VCS) since Git can do everything for both local and remote source code management.
Debian は Debian Salsa サービス経由でフリーの Git サービスを提供します。その説明文書は https://wiki.debian.org/Salsa にあります。
Here are some Git related packages.
表10.11 git 関連のパッケージとコマンドのリスト
パッケージ | ポプコン | サイズ | コマンド | 説明 |
---|---|---|---|---|
git
|
V:305, I:517 | 44453 | git (7) |
git: 高速、スケーラブル、分散型リビジョンコントロールシステム |
gitk
|
V:4, I:36 | 1792 | gitk (1) |
GUI による履歴付き Git レポジトリーブラウザー |
git-gui
|
V:1, I:20 | 2386 | git-gui (1) |
Git 用の GUI (履歴無し) |
git-email
|
V:0, I:10 | 1040 | git-send-email (1) |
Git からパッチの集合の email として送信 |
git-buildpackage
|
V:1, I:10 | 7351 | git-buildpackage (1) |
Git を使って Debian パッケージ化を自動化 |
dgit
|
V:0, I:1 | 487 | dgit (1) |
git interoperability with the Debian archive |
imediff
|
V:0, I:0 | 169 | git-ime (1) |
interactive git commit split helper tool |
stgit
|
V:0, I:0 | 601 | stg (1) |
Git 上の quilt (Python) |
git-doc
|
I:13 | 12989 | N/A | 正式 Git 文書 |
gitmagic
|
I:0 | 721 | N/A | "Git マジック"、Git に関する分かり易いガイド |
Git は使うあなたの名前や email アドレス等を "~/.gitconfig
"
中のいくつかのグローバル設定に設定したいなら次のようにします。
$ git config --global user.name "Name Surname" $ git config --global user.email yourname@example.com
You may also customize the Git default behavior by the following.
$ git config --global init.defaultBranch main $ git config --global pull.rebase true $ git config --global push.default current
もしあなたが CVS や Subversion コマンドに慣れ過ぎている場合には、いくつかのコマンドエイリアスを次のように設定するのも一計です。
$ git config --global alias.ci "commit -a" $ git config --global alias.co checkout
あなたのグローバル設定は次のようにするとチェックできます。
$ git config --global --list
Git operation involves several data.
The working tree which holds user facing files and you make changes to them.
The changes to be recorded must be explicitly selected and staged to the
index. This is git add
and git rm
commands.
The index which holds staged files.
Staged files will be committed to the local repository upon the subsequent
request. This is git commit
command.
The local repository which holds committed files.
Git records the linked history of the committed data and organizes them as branches in the repository.
The local repository can send data to the remote repository by git
push
command.
The local repository can receive data from the remote repository by
git fetch
and git pull
commands.
The git pull
command performs git
merge
or git rebase
command after git
fetch
command.
Here, git merge
combines two separate branches of history
at the end to a point. (This is default of git pull
without customization and may be good for upstream people who publish branch
to many people.)
Here, git rebase
creates one single branch of sequential
history of the remote branch one followed by the local branch one. (This is
pull.rebase true
customization case and may be good for
rest of us.)
The remote repository which holds committed files.
The communication to the remote repository uses secure communication protocols such as SSH or HTTPS.
The working tree is files outside of the .git/
directory. Files inside of the .git/
directory hold the
index, the local repository data, and some git configuration text files.
Here is an overview of main Git commands.
表10.12 Main Git commands
Git command | 機能 |
---|---|
git init |
(ローカル) レポジトリーを作成 |
git clone URL |
clone the remote repository to a local repository with the working tree |
git pull origin main |
update the local main branch by the remote repository
origin |
git add . |
add file(s) in the working tree to the index for pre-existing files in index only |
git add -A . |
add file(s) in the working tree to the index for all files including removals |
git rm filename |
remove file(s) from the working tree and the index |
git commit |
commit staged changes in the index to the local repository |
git commit -a |
add all changes in the working tree to the index and commit them to the local repository (add + commit) |
git push -u origin branch_name |
update the remote repository origin by the local
branch_name branch (initial invocation) |
git push origin branch_name |
update the remote repository origin by the local
branch_name branch (subsequent invocation) |
git diff treeish1 treeish2 |
show difference between treeish1 commit and treeish2 commit |
gitk |
GUI display of VCS repository branch history tree |
Here are some Git tips.
表10.13 Git tips
Git command line | 機能 |
---|---|
gitk --all |
see complete Git history and operate on them such as resetting HEAD to another commit, cheery-picking patches, creating tags and branches ... |
git stash |
get the clean working tree without loosing data |
git remote -v |
check settings for remote |
git branch -vv |
check settings for branch |
git status |
show working tree status |
git config -l |
list git settings |
git reset --hard HEAD; git clean -x -d -f |
revert all working tree changes and clean them up completely |
git rm --cached filename |
revert staged index changed by git add filename |
git reflog |
get reference log (useful for recovering commits from the removed branch) |
git branch new_branch_name HEAD@{6} |
create a new branch from reflog information |
git remote add new_remote URL |
add a new_remote remote repository pointed by URL |
git remote rename origin upstream |
rename the remote repository name from origin to
upstream |
git branch -u upstream/branch_name |
set the remote tracking to the remote repository upstream
and its branch name branch_name . |
git remote set-url origin https://foo/bar.git |
change URL of origin |
git remote set-url --push upstream DISABLED |
disable push to upstream (Edit
.git/config to re-enable) |
git checkout -b topic_branch ; git push -u topic_branch
origin |
make a new topic_branch and push it to
origin |
git branch -m oldname newname |
rename local branch name |
git push -d origin branch_to_be_removed |
remove remote branch (new method) |
git push origin :branch_to_be_removed |
remove remote branch (old method) |
git checkout --orphan unconnected |
create a new unconnected branch |
git fetch upstream foo:upstream-foo |
create a local (possibly orphan) upstream-foo branch as a
copy of foo branch the upstream
repository |
git rebase -i origin/main |
reorder/drop/squish commits from origin/main to clean
branch history |
git reset HEAD^; git commit --amend |
squash last 2 commits into one |
git checkout topic_branch ; git merge --squash topic_branch
|
squash entire topic_branch into a commit |
git fetch --unshallow --update-head-ok origin
'+refs/heads/*:refs/heads/*' |
convert a shallow clone to the full clone of all branches |
git ime |
split the last commit into a series of file-by-file smaller commits
etc. (imediff package required) |
git repack -a -d; git prune |
repack the local repository into single pack (this may limit chance of lost data recovery from erased branch etc.) |
![]() |
警告 |
---|---|
たとえ |
![]() |
注意 |
---|---|
If a local branch which has been pushed to remote repository is rebased or
squashed, pushing this branch has risks and requires
|
![]() |
注意 |
---|---|
|
![]() |
ヒント |
---|---|
If there is a executable file |
次を参照下さい。
マンページ: git(1)
(/usr/share/doc/git-doc/git.html
)
Git ユーザーマニュアル
(/usr/share/doc/git-doc/user-manual.html
)
git へのチュートリアル導入
(/usr/share/doc/git-doc/gittutorial.html
)
git へのチュートリアル導入: 第2部
(/usr/share/doc/git-doc/gittutorial-2.html
)
Everyday GIT With 20 Commands
Or So (/usr/share/doc/git-doc/giteveryday.html
)
Git マジック
(/usr/share/doc/gitmagic/html/index.html
)
The version control systems (VCS) is sometimes known as the revision control system (RCS), or the software configuration management (SCM).
Here is a summary of the notable other non-Git VCS on the Debian system.
表10.14 List of other version control system tools
パッケージ | ポプコン | サイズ | ツール | VCS タイプ | コメント |
---|---|---|---|---|---|
mercurial
|
V:5, I:37 | 2013 | Mercurial | 分散型 | Python と一部 C で書かれた DVCS |
darcs
|
V:0, I:6 | 34070 | Darcs | 分散型 | パッチに関して賢い計算をする DVCS (遅い) |
bzr
|
I:11 | 28 | Bazaar | 分散型 | DVCS influenced by tla written in Python (historic) |
tla
|
V:0, I:1 | 1022 | GNU arch | 分散型 | DVCS mainly by Tom Lord (historic) |
subversion
|
V:15, I:86 | 4838 | Subversion | リモート | "CVS done right", newer standard remote VCS (historic) |
cvs
|
V:3, I:32 | 4620 | CVS | リモート | previous standard remote VCS (historic) |
tkcvs
|
V:0, I:1 | 1498 | CVS, … | リモート | VCS (CVS, Subversion, RCS) レポジトリーツリーの GUI 表示 |
rcs
|
V:2, I:16 | 564 | RCS | ローカル | "Unix SCCS done right" (historic) |
cssc
|
V:0, I:2 | 2044 | CSSC | ローカル | clone of the Unix SCCS (historic) |
[4] A write-once media such as CD/DVD-R can prevent overwrite accidents. (See 「バイナリーデーター」 for how to write to the storage media from the shell commandline. GNOME desktop GUI environment gives you easy access via menu: "Places→CD/DVD Creator".)
[5] Some of these data can not be regenerated by entering the same input string to the system.
[6] If you use "~/.vimrc
" instead of
"~/.vim/vimrc
", please substitute accordingly.