• このエントリーをはてなブックマークに追加


メモ

何年も昔に FTP で上げっぱなし(そしてローカルでは行方不明)だったものを,とりあえず手元の環境に引っぱってくる.バージョン管理されていないので,最低限「どのファイルがいつ頃のものか」くらいの情報としてタイムスタンプは保持しておきたい.

PathFinder(普通に Finder でも) とかで FTP リモートをマウントしてから rsync してみたが,ファイルを 5 〜 6 転送したあたりで毎回刺さる.サーバ側の問題?ともかく,ファイルは 5000 以上あるのでやってられん.

FileZilla の「転送したファイルのタイムスタンプを維持」機能:

ss-1391586155

で,ファイルのタイムスタンプは無問題だったが,ディレクトリのタイムスタンプが「now」になってしまう.そこさえなんとかなれば.

幸い,tree -dD /Volumes/ftpremote とかして,リモート側のツリー構造とタイムスタンプの情報は得られたので,これを料理して touch -t {time} {directory} できるように持っていき,まぁなんとかなった.

料理の記録

タイムスタンプとフルパスだけを抽出する練習.

\tree -df -NaD --timefmt='%Y-%m-%d %H:%M' {source_tree} \
    | grep -E '\[[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\]' \
    | perl -pe 's!^.*\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2})\][^/]*(.*)$!$1 -- $2!'
% \tree -df -NaD --timefmt='%Y-%m-%d %H:%M' /Users/issm/Dropbox/blogdrafts \
    | grep -E '\[[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\]' \
    | perl -pe 's!^.*\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2})\][^/]*(.*)$!$1 -- $2!'
2012-06-13 11:25 -- /Users/issm/Dropbox/blogdrafts/2007
2012-01-26 19:37 -- /Users/issm/Dropbox/blogdrafts/2008
2012-06-13 11:26 -- /Users/issm/Dropbox/blogdrafts/2009
2012-06-13 11:28 -- /Users/issm/Dropbox/blogdrafts/2010
2012-06-13 11:23 -- /Users/issm/Dropbox/blogdrafts/2010/codes
2013-01-24 13:59 -- /Users/issm/Dropbox/blogdrafts/2011
2012-06-13 11:19 -- /Users/issm/Dropbox/blogdrafts/2011/codes
2012-06-13 11:23 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod
2012-06-13 11:20 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git
2012-06-13 11:25 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/hooks
2012-06-13 11:21 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/info
2012-06-13 11:20 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs
2012-06-13 11:19 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs/refs
2012-06-13 11:20 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs/refs/heads
2012-06-13 11:19 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects
2012-06-13 11:20 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/02
2012-06-13 11:21 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/31
2012-06-13 11:21 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/79
2012-06-13 11:20 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/7c
2011-05-19 18:59 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/info
2011-05-19 18:59 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/pack
2012-06-13 11:19 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs
2012-06-13 11:20 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs/heads
2011-05-19 18:59 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs/tags
2012-06-13 11:23 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-06-05--cpanbook
2012-06-13 11:22 -- /Users/issm/Dropbox/blogdrafts/2011/codes/2011-12-07--cache-filecache
2012-12-19 23:29 -- /Users/issm/Dropbox/blogdrafts/2012
2012-08-30 19:25 -- /Users/issm/Dropbox/blogdrafts/2012/code
2013-12-06 15:23 -- /Users/issm/Dropbox/blogdrafts/2013
2013-01-13 16:47 -- /Users/issm/Dropbox/blogdrafts/2013/code
2013-01-13 16:48 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2
2013-01-13 17:53 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp
2013-01-13 18:15 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git
2013-01-13 16:48 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/hooks
2013-01-13 16:48 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/info
2013-01-13 16:48 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/logs
2013-01-13 16:48 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/logs/refs
2013-01-13 16:48 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/logs/refs/heads
2013-01-13 16:48 -- /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/objects
...

実際に実行するコマンドを生成する.

\tree -df -NaD --timefmt='%Y%m%d%H%M' {source_tree} \
    | grep -E '\[[0-9]{12}\]' \
    | perl -pe 's!^.*\[(\d{12})\][^/]*(.*)$![ -d $2 ] && touch -t $1 $2!' \
    | perl -pe 's!{source_tree}!{target_tree}!g'
% \tree -df -NaD --timefmt='%Y%m%d%H%M' /Users/issm/Dropbox/blogdrafts \
    | grep -E '\[[0-9]{12}\]' \
    | perl -pe 's!^.*\[(\d{12})\][^/]*(.*)$![ -d $2 ] && touch -t $1 $2!g' \
    | perl -pe 's!/Users/issm/Dropbox/blogdrafts!/path/to/target!' \
    > /path/to/bulk_touch.sh

/path/to/bulk_touch.sh:

[ -d /path/to/target/2007 ] && touch -t 201206131125 /Users/issm/Dropbox/blogdrafts/2007
[ -d /path/to/target/2008 ] && touch -t 201201261937 /Users/issm/Dropbox/blogdrafts/2008
[ -d /path/to/target/2009 ] && touch -t 201206131126 /Users/issm/Dropbox/blogdrafts/2009
[ -d /path/to/target/2010 ] && touch -t 201206131128 /Users/issm/Dropbox/blogdrafts/2010
[ -d /path/to/target/2010/codes ] && touch -t 201206131123 /Users/issm/Dropbox/blogdrafts/2010/codes
[ -d /path/to/target/2011 ] && touch -t 201301241359 /Users/issm/Dropbox/blogdrafts/2011
[ -d /path/to/target/2011/codes ] && touch -t 201206131119 /Users/issm/Dropbox/blogdrafts/2011/codes
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod ] && touch -t 201206131123 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git ] && touch -t 201206131120 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/hooks ] && touch -t 201206131125 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/hooks
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/info ] && touch -t 201206131121 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/info
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs ] && touch -t 201206131120 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs/refs ] && touch -t 201206131119 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs/refs
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs/refs/heads ] && touch -t 201206131120 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/logs/refs/heads
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects ] && touch -t 201206131119 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/02 ] && touch -t 201206131120 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/02
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/31 ] && touch -t 201206131121 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/31
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/79 ] && touch -t 201206131121 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/79
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/7c ] && touch -t 201206131120 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/7c
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/info ] && touch -t 201105191859 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/info
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/pack ] && touch -t 201105191859 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/objects/pack
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs ] && touch -t 201206131119 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs/heads ] && touch -t 201206131120 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs/heads
[ -d /path/to/target/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs/tags ] && touch -t 201105191859 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-05-19.dbix-skinny-schema-loader-mod/.git/refs/tags
[ -d /path/to/target/2011/codes/2011-06-05--cpanbook ] && touch -t 201206131123 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-06-05--cpanbook
[ -d /path/to/target/2011/codes/2011-12-07--cache-filecache ] && touch -t 201206131122 /Users/issm/Dropbox/blogdrafts/2011/codes/2011-12-07--cache-filecache
[ -d /path/to/target/2012 ] && touch -t 201212192329 /Users/issm/Dropbox/blogdrafts/2012
[ -d /path/to/target/2012/code ] && touch -t 201208301925 /Users/issm/Dropbox/blogdrafts/2012/code
[ -d /path/to/target/2013 ] && touch -t 201312061523 /Users/issm/Dropbox/blogdrafts/2013
[ -d /path/to/target/2013/code ] && touch -t 201301131647 /Users/issm/Dropbox/blogdrafts/2013/code
[ -d /path/to/target/2013/code/2013-01-13.amon2 ] && touch -t 201301131648 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp ] && touch -t 201301131753 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp/.git ] && touch -t 201301131815 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp/.git/hooks ] && touch -t 201301131648 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/hooks
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp/.git/info ] && touch -t 201301131648 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/info
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp/.git/logs ] && touch -t 201301131648 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/logs
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp/.git/logs/refs ] && touch -t 201301131648 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/logs/refs
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp/.git/logs/refs/heads ] && touch -t 201301131648 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/logs/refs/heads
[ -d /path/to/target/2013/code/2013-01-13.amon2/MyApp/.git/objects ] && touch -t 201301131648 /Users/issm/Dropbox/blogdrafts/2013/code/2013-01-13.amon2/MyApp/.git/objects
(ry)

sh /path/to/bulk_touch.sh で “last modification time” をまとめて変更,とかそんな感じ.