From 551eaee2ff4986e925da4917925e3a8bd0b00c0f Mon Sep 17 00:00:00 2001 From: Charl Smit Date: Thu, 4 Apr 2024 16:02:38 +0200 Subject: [PATCH 1/4] Create sample Linux script --- examples/scheduled_run_linux.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 examples/scheduled_run_linux.sh diff --git a/examples/scheduled_run_linux.sh b/examples/scheduled_run_linux.sh new file mode 100644 index 00000000..6da6cc06 --- /dev/null +++ b/examples/scheduled_run_linux.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +commcare-export --output-format \ + --output \ + --query \ + --project \ + --commcare-hq https://commcarehq.org \ + --auth-mode apikey \ + --password \ From 8f15f0111c8b30c89cdf994c1503cfa24b26a9eb Mon Sep 17 00:00:00 2001 From: Charl Smit Date: Thu, 4 Apr 2024 16:16:54 +0200 Subject: [PATCH 2/4] Add example bat file --- examples/scheduled_run_windows.bat | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/scheduled_run_windows.bat diff --git a/examples/scheduled_run_windows.bat b/examples/scheduled_run_windows.bat new file mode 100644 index 00000000..4a35f580 --- /dev/null +++ b/examples/scheduled_run_windows.bat @@ -0,0 +1,7 @@ +commcare-export --output-format ^ + --output ^ + --query ^ + --project ^ + --commcare-hq https://commcarehq.org ^ + --auth-mode apikey ^ + --password ^ From 259f511fefc41a6dd7d87379c8158bf02e88faaa Mon Sep 17 00:00:00 2001 From: Charl Smit Date: Thu, 4 Apr 2024 16:17:59 +0200 Subject: [PATCH 3/4] Remove multi-line symbol from last line --- examples/scheduled_run_linux.sh | 2 +- examples/scheduled_run_windows.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/scheduled_run_linux.sh b/examples/scheduled_run_linux.sh index 6da6cc06..b485f0fc 100644 --- a/examples/scheduled_run_linux.sh +++ b/examples/scheduled_run_linux.sh @@ -6,4 +6,4 @@ commcare-export --output-format \ --project \ --commcare-hq https://commcarehq.org \ --auth-mode apikey \ - --password \ + --password diff --git a/examples/scheduled_run_windows.bat b/examples/scheduled_run_windows.bat index 4a35f580..2ed1c2b5 100644 --- a/examples/scheduled_run_windows.bat +++ b/examples/scheduled_run_windows.bat @@ -4,4 +4,4 @@ commcare-export --output-format ^ --project ^ --commcare-hq https://commcarehq.org ^ --auth-mode apikey ^ - --password ^ + --password From 4a6f2fa900f2438682049c9e3f6b6b20633365db Mon Sep 17 00:00:00 2001 From: Charl Smit Date: Fri, 5 Apr 2024 09:16:05 +0200 Subject: [PATCH 4/4] Update README with scheduled runs --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index f12418fa..19a0fd89 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,49 @@ you will change the columns of the 'commcare_locations' table and it is very likely you will want to drop the table before exporting with the new organization. +Scheduling the DET +------------------ +Scheduling the DET to run at regular intervals is a useful tactic to keep your +database up to date with CommCare HQ. + +A common approach to scheduling DET runs is making use of the operating systems' scheduling +libraries to invoke a script to execute the `commcare-export` command. Sample scripts can be +found in the `examples/` directory for both Windows and Linux. + +### Windows +On Windows systems you can make use of the [task scheduler](https://sqlbackupandftp.com/blog/how-to-schedule-a-script-via-windows-task-scheduler/) +to run scheduled scripts for you. + +The `examples/` directory contains a sample script file, `scheduled_run_windows.bat`, which can be used by the +task scheduler to invoke the `commcare-export` command. + +To set up the scheduled task you can follow the steps below. +1. Copy the file `scheduled_run_windows.bat` to any desired location on your system (e.g. `Documents`) +2. Edit the copied `.bat` file and populate your own details +3. Follow the steps outlined [here](https://sqlbackupandftp.com/blog/how-to-schedule-a-script-via-windows-task-scheduler/), +using the .bat file when prompted for the `Program/script`. + + +### Linux +On a Linux system you can make use of the [crontab](https://www.techtarget.com/searchdatacenter/definition/crontab) +command to create scheduled actions (cron jobs) in the system. + +The `examples/` directory contains a sample script file, `scheduled_run_linux.sh`, which can be used by the cron job. +To set up the cron job you can follow the steps below. +1. Copy the example file to the home directory +> cp ./examples/scheduled_run_linux.sh ~/scheduled_run_linux.sh +2. Edit the file to populate your own details +> nano ~/scheduled_run_linux.sh +3. Create a cron job by appending to the crontab file +> crontab -e + +Make an entry below any existing cron jobs. The example below executes the script file at the top of +every 12th hour of every day +> 0 12 * * * bash ~/scheduled_run_linux.sh + +You can consult the [crontab.guru](https://crontab.guru/) tool which is very useful to generate and interpret +any custom cron schedules. + Python Library Usage --------------------