投稿

8月, 2015の投稿を表示しています

PowerShellからS3に同期

うーん。 なんというか文字コードに悩まされた。 後はタスクスケジューラに仕込んで動くかどうかだが・・・・。 ちなみにそのままAWSのツールインストールすると文字化けするので PythonからAWSのCLIは入れなおしてます。 http://dev.classmethod.jp/cloud/aws/awscli-for-windows/ んで、PowerShellではまるとは・・・。 ISEだと文字化けしないけどPowerShellコンソールから 動かすと日本語ファイルがあると文字化けするんだよな~。 けどイベントビューアに出力するようにしたから start-transcript $logfileと日本語文字化けのとこはいいや・・・。 $frompath = "C:\Users\Administrator\Desktop\work" $tosite = "s3:S3バケット名" $logfile = "C:\work\Console.log" $pythonpPath = "C:\Python34\Scripts" $errKeyword = "Completed 1 part(s) with ... file(s) remaining" $worningKeyword = "Completed 0 part(s) with ... file(s) remaining" start-transcript $logfile cd $pythonpPath $result = .\aws s3 sync $frompath $tosite $result | Out-File $logfile -Append -Encoding utf8 stop-transcript #S3から返されたエラーに応じた処理 switch ($result){ $errKeyword{ $ErrMsg = "S3Syncでエラーが発生しました。バゲット接続エラー。"+ "`n" + $result Write-EventLog -LogName S3Sync