gzipは、ファイルの圧縮はできるがディレクトリの圧縮はできない。
ディレクトリを圧縮する場合はtarでアーカイブしてからgzip圧縮する(tarのzオプション)。
ディレクトリ圧縮は、ターゲットのディレクトリがある場所までcdしてから実行するのが安全。
ref. https://daybreaksnow.hatenablog.jp/entry/2014/03/01/204940
# 圧縮
$ tar -zcvf sample.tar.gz sample_dir
# 解凍 ワーキングディレクトリに sample_dirが作成される
$ tar -zxvf sample.tar.gz
上記の方法はシンボリックリンクのリンク先はアーカイブに含めない。 vオプションは必須ではないが進行状況を確認する意味で付与するのがおすすめ。
c アーカイブを新規に作成するx アーカイブを解答するz zip形式で圧縮するf アーカイブファイル名を指定する(fオプションは必ず最後に指定する czf => OK cfz => NG)v 処理したファイルを詳しく出力するref.
--excludepattern
Do not process files or directories that match the specified pattern. Note that exclusions take precedence over
patterns or filenames specified on the command line.
ref. man tar
ref.
$ man tar
-h (c and r mode only) Synonym for -L.
-L, --dereference (c and r mode only) All symbolic links will be followed. Nor- mally, symbolic links are archived as such. With this option, the target of the link will be archived instead.
filectime()は、解凍した日付filemtime()は、サーバーのタイムスタンプを維持EC-CUBE 4から直下のvarディレクトリを除外
find . -type d -name "var"
./var
./vendor/bheller/images-generator/var
./varのみを除外
# NG
# 直下のvarディレクトリ以外も除外される
# --exclude ./var/ も同様 NG
# --exclude var/ も同様NG
$ tar --exclude ./var -zcvf ec-cube-4.1.2.tar.gz ec-cube-4.1.2
$ ll ec-cube-4.1.2
drwxrwxrwx 4 shiroshi staff 128B 2 23 12:01 cache
-rw-r--r-- 1 shiroshi staff 928K 2 23 11:34 eccube.db
drwxrwxrwx 3 shiroshi staff 96B 2 23 11:34 log
drwxrwxrwx 4 shiroshi staff 128B 2 23 12:01 sessions
以下のように指定する。
$ tar --exclude ./var/cache --exclude ./var/log --exclude ./var/sessions -zcvf ec-cube-4.1.2.tar.gz ec-cube-4.1.2
# .gitも削除
$ tar --exclude ./var/cache --exclude ./var/log --exclude ./var/sessions --exclude ./.git -zcvf ec-cube-4.1.2.tar.gz ec-cube-4.1.2
除外リストを作成
./var/cache
./var/log
./var/sessions
./.git
$ tar -X excludes.txt -zcvf ec-cube-4.1.2.tar.gz ec-cube-4.1.2