空ディレクトリとドットファイルを含めて大量ファイルをtarでアーカイブする
単純に tar でアーカイブしようとすると、ドットファイルが含まれない。
単純に find ${path} -f を使うと空ディレクトリが含まれない。
大量のファイルの場合、ファイルリストを取り込みきれない。
xargs や $(find ...) ではメモリ上にファイルリストを置いてしまうのでダメ
ソケットなどを除外したい。
シンボリックリンクを解決して普通のファイル/ディレクトリとしてアーカイブする場合
-h, --dereference オプション
シンボリックリンクをシンボリックリンクのままでアーカイブする場合
オプション不要
圧縮方式
table:圧縮方式
拡張子 形式 オプション
Z compress(LZW) Z
gz(tgz) gzip z
bz2 bzip2 j
xz xz J
最近の tar だと aオプションで拡張子から自動的に判定することができるらしい。
code:console
Compression options
-a, --auto-compress
Use archive suffix to determine the compression program.
とりあえず、まずは以下で行けるはず。
$ find ${path} -print0 | tar -cva -f myarchive.tar.gz --null -T -
--null が -T より後だと以下のようなエラーが出た。
code:console
tar: The following options were used after any non-optional arguments in archive create or update mode. These options are positional and affect only arguments that follow them. Please, rearrange them properly.
tar: --null has no effect
tar: Exiting with failure status due to previous errors