0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Amazon Linux 2でcronを使ってバッチ処理を実行する

0
Posted at

目的

Amazon Linux 2のEC2インスタンスを利用してアプリをデプロイする際にバッチ処理でデータベースのバックアップを取りたいと思い備忘録。

前提

Amazon Linux 2ではバッチ処理をするためのcronが標準インストールされている。

バッチ処理の設定をする

設定ファイルを開く

$ crontab -e

書き込む

毎月1日の0時00分にバッチ処理を動かす場合

0 0 1 * * source ~/venv/bin/activate; 
cd ~/test_app; 
# 標準出力と標準エラー出力をcron.logというファイルに書き出すようにする
python manage.py backup_test > ~/cron.log 2>&1

書式以下のようになっている。

<分><時><日><月><曜日><実行したいコマンド>

まとめ

バッチ処理の実装は業務では当たり前のことではあるが、なかなか個人で実装することがないと思うので、実装してみた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?