lsyncdとawscliでS3にファイルを同期する
こんな感じ。
s3sync = { maxProcesses = 1, onStartup = "aws s3 sync ^source ^target", onCreate = "[ -f ^source^pathname ] && aws s3 cp ^source^pathname ^target^pathname || true", onModify = "[ -f ^source^pathname ] && aws s3 cp ^source^pathname ^target^pathname || true", onDelete = "[ -f ^source^pathname ] && aws s3 rm ^target^pathname || true", onMove = "aws s3 mv ^target^o.pathname ^target^d.pathname", } sync { s3sync, source = "/path/to/source", target = "s3://your-bucket-name/path/to/target", }
キモとしては次の2点:
- S3にはディレクトリというものがないので、ファイルだけを同期するようにする
--recursive
をつけると失敗する。とはいえlsyncdはファイルごとにキューに入れてくれるので不要
時々S3側のエラーなのかコマンド実行に失敗してlsyncdごと止まることがあるので、monitでlsyncdを監視して適宜再起動するようにした。
ちなみにonMove
を設定してはみたものの、mv
してみてもonDelete
とonCreate
が呼ばれるだけだった。
s3cmdで同期する場合はsuz-lab - blog: "lsyncd"でS3と同期を参照。