■指定ディレクトリ配下を同期バックアップ(zip)
毎回世代管理していても仕方の無いバックアップの場合。
最新版だけが欲しい場合に便利。
細かい制御をどうするかは列挙するとキリが無いので、お好きなように。
以下、スルーした箇所もヘルプやマニュアルに対処方法となるオプションがあります。
要は手元にあるのが1ファイルのzipで済むというだけで、
出来たzipファイルを別マシンへのコピーする際に日付を付与するなどして世代管理をしても構いません。
■作成、更新、削除、確認方法。
ローカルなgitディレクトリの同期バックアップ。
Windows上で動作するgowとWindows版squidの「var\logs」の同期バックアップ。
参考:gow
https://github.com/bmatzelle/gow
■debian(squeeze)の場合、zipの導入。
$ apt-cache show ^zip\$ | grep Desc -A 7
Description-ja: .zip ファイル用のアーカイバ
本パッケージは InfoZip の zip プログラムです。良く知られた PKZIP
プログラムと完全互換性を持ちますが、コマンドラインオプションは
全く同じではありません。すなわち、出力結果は同じでも、手段は
異なります。
.
本バージョンは暗号化された zip ファイルをサポートしています。
Homepage: http://www.info-zip.org/Zip.html
$ sudo apt-get update zip
■オプションのヘルプ(debian)
$ cat /etc/debian_version; \
6.0.6
$ zip -v | head -2
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
$ zip -h2 | grep "^ *\-FS\|^ *\-r" | head -2
-FS filesync - update if date or size changed, delete if no OS match
-r recurse into directories (see Recursion below)
■オプションのヘルプ(Windows)
> whereis zip
C:\myapp\Gow\bin\zip.exe
> zip -v | head -2
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
> zip -h2 | grep "^ *\-FS\|^ *\-r" | head -2
-FS filesync - update if date or size changed, delete if no OS match
-r recurse into directories (see Recursion below)
■「git_working」を対象とする(debian)。
$ cat myscripts/git_archive.sh
if [ "x$HOME" == "x" ];then
echo "Error: HOME Not Set!" >&2
exit 1
fi
cd ~/
zip -FS -r git_working.zip git_working
■初回実行時(debian)
$ /bin/bash -x myscripts/git_archive.sh 2>&1 | sed s/"`whoami`"/"dummy"/g
+ '[' x/home/dummy == x ']'
+ cd /home/dummy/
+ zip -FS -r git_working.zip git_working
adding: git_working/ (stored 0%)
adding: git_working/winsquid_blacklist/ (stored 0%)
adding: git_working/winsquid_blacklist/blacklist_regex (deflated 45%)
adding: git_working/winsquid_blacklist/blacklist (deflated 43%)
adding: git_working/work/ (stored 0%)
adding: git_working/work/smallfirewall (deflated 67%)
adding: git_working/work/iptables.ja.txt (deflated 72%)
...
■2回目(debian)
$ /bin/bash -x myscripts/git_archive.sh 2>&1 | sed s/"`whoami`"/"dummy"/g
+ '[' x/home/dummy == x ']'
+ cd /home/dummy/
+ zip -FS -r git_working.zip git_working
Archive is current
■テストファイルの作成とバックアップ(debian)
$ touch git_working/test
$ /bin/bash -x myscripts/git_archive.sh 2>&1 | sed s/"`whoami`"/"dummy"/g
+ '[' x/home/dummy == x ']'
+ cd /home/dummy/
+ zip -FS -r git_working.zip git_working
updating: git_working/ (stored 0%)
adding: git_working/test (stored 0%)
■テストファイルの変更とバックアップ(debian)
$ echo "111111111111111111" > git_working/test
$ /bin/bash -x myscripts/git_archive.sh 2>&1 | sed s/"`whoami`"/"dummy"/g
+ '[' x/home/dummy == x ']'
+ cd /home/dummy/
+ zip -FS -r git_working.zip git_working
updating: git_working/test (deflated 68%)
■テストファイルの削除とバックアップ(debian)
$ rm git_working/test
$ /bin/bash -x myscripts/git_archive.sh 2>&1 | sed s/"`whoami`"/"dummy"/g
+ '[' x/home/dummy == x ']'
+ cd /home/dummy/
+ zip -FS -r git_working.zip git_working
updating: git_working/ (stored 0%)
deleting: git_working/test
■「squid\var\logs」を対象とした初回実行時。
※pidは要らないけど、ここではスルー。
> cd /d d:\squid\var
> zip -FS -r logs.zip logs
adding: logs/ (256 bytes security) (stored 0%)
adding: logs/access.log (148 bytes security) (deflated 94%)
adding: logs/access.log.0 (148 bytes security) (deflated 94%)
adding: logs/access.log.1 (148 bytes security) (deflated 94%)
adding: logs/access.log.2 (148 bytes security) (deflated 94%)
adding: logs/cache.log (148 bytes security) (deflated 89%)
...
■テストファイルの作成(Windows)
※プロキシが稼動中なので、access.logやstore.logも除外出来ますが、これもスルー。
> touch logs\test
> zip -FS -r logs.zip logs
updating: logs/ (256 bytes security) (stored 0%)
updating: logs/access.log (148 bytes security) (deflated 94%)
adding: logs/test (188 bytes security) (stored 0%)
■テストファイルの更新
> echo "111111111111" > logs\test
> zip -FS -r logs.zip logs
updating: logs/access.log (148 bytes security) (deflated 94%)
updating: logs/test (188 bytes security) (deflated 47%)
■テストファイルの削除
> del logs\test
■確認方法(debian/Windows)
$ zip --test git_working.zip
test of git_working.zip OK
> zip --test logs.zip
test of logs.zip OK
$ zip -sf git_working.zip | tail -5
git_working/sa_report/README.md
git_working/sa_report/cpu_gnuplot.sh
git_working/sa_report/autoclear.sh
git_working/sa_report/swapcheck.sh
Total 1806 entries (16289051 bytes)
> zip -sf logs.zip
Archive contains:
logs/
logs/access.log
logs/access.log.0
logs/access.log.1
logs/access.log.2
logs/cache.log
logs/cache.log.0
logs/cache.log.1
logs/cache.log.2
logs/squid.pid
logs/store.log
logs/store.log.0
logs/store.log.1
logs/store.log.2
Total 12 entries (770707344 bytes)
■おまけ(Windowsのバッチ)
まあ、そのままなので、書く必要も無いかと思いますが。。。
> type logs_zip.bat
@echo off
cd /d d:\squid\var
zip -FS -r logs.zip logs
> logs_zip.bat
updating: logs/access.log (148 bytes security) (deflated 94%)
updating: logs/test (188 bytes security) (deflated 47%)