From 128cc7e06d20a43ab2227409ebe35dfa6f8c5182 Mon Sep 17 00:00:00 2001 From: blitter Date: Tue, 27 Jun 2023 10:01:06 +0200 Subject: [PATCH 1/7] restart.sh --- README.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 397b517..103c735 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,8 @@ secrets (Don't forgot to ignore whatever intermediate files your editor produces.) +Either way, you might want to restart the (regurlarly running `termux-scheduler`) job whenever you pulled some changes. For now, I recommend cancelling the old job manually and having a `restart.sh` script ready, containing the command described in [the section on the regurlarly running job](#regurlarly-running-the-backup-job). + If you are still reading this, and you wonder why this is so complicated – so do I. Please reach out if you have a better idea. @@ -171,13 +173,6 @@ in the tmux shell from the directory of this repository. `--BORGBACKUP_FORCE 1` (the value `1` can be replaced by any except `0`) attempts to execute backup even though the constraints are not fulfilled. - -### how to start/stop job - -* cmd start -* cmd stop -* cmd to see if running - ### On Nightly Versions On the branch [`nightly`](https://gitlab.com/blitter/tbo-cli/-/tree/nightly) the features for the next version will slowly be added. Yes, that includes breaking changes. @@ -201,8 +196,6 @@ termux-job-scheduler \ The directory has to be the absolute path. (May begin with `~`.) - - How to see if a cron job is currently running: (shows jobs and their ids) ```sh -- GitLab From 2c44c84dea8adff25c04e256adcf35394497dc15 Mon Sep 17 00:00:00 2001 From: blitter Date: Tue, 27 Jun 2023 10:23:47 +0200 Subject: [PATCH 2/7] regurlar job updates --- README.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 103c735..83bc343 100644 --- a/README.md +++ b/README.md @@ -143,12 +143,13 @@ The general idea is to put the `configuration` on all devices. There are multipl ln -s secrets/ src/secrets ``` - Don't forgot to pull the submodule. Clone with the option `--recurse-submodules`. Update the submodule from time to time (and update your config accordingly). + Don't forgot to pull the submodule. Clone and pull with the option `--recurse-submodules`. Update the submodule from time to time (and update your config accordingly). Here is an example `.gitignore` for your repository: ``` secrets +config/hostname .kate-swp ``` @@ -188,7 +189,7 @@ Here is an example scheduled job to run on the server for running a compact once ```sh termux-job-scheduler \ - --script \ + --script \ --period-ms 1800000 \ --network unmetered \ --persisted true @@ -196,6 +197,22 @@ termux-job-scheduler \ The directory has to be the absolute path. (May begin with `~`.) + +You can create a `restart.sh` doing these steps automated. Execute it using `bash restart.sh`. + +```sh +BACKUP_SCRIPT= + +chmod u+x $BACKUP_SCRIPT + +termux-job-scheduler \ + --script $BACKUP_SCRIPT \ + --period-ms 1800000 \ + --network unmetered \ + --persisted true +``` + + How to see if a cron job is currently running: (shows jobs and their ids) ```sh @@ -205,7 +222,7 @@ termux-job-scheduler -p How to stop the job: ```sh -termux-job-scheduler --cancel +termux-job-scheduler --cancel --job-id # or termux-job-scheduler --cancel-all ``` @@ -259,7 +276,7 @@ This very first version of the TBo-CLI makes some assumptions that cannot be cha These assumptions can only be changed by manipulating the script. Some of these assumptions will be moved to the configuration in later versions. -## Assumptions of the "cron" job +## Assumptions of the scheduled job * Backups should only be attempted after 3 am. * When not having created a backup on a server yet, retry every 30 minutes. -- GitLab From 7eb1c61713b57a84cb0c5f4c5ab19259fa9cb8bb Mon Sep 17 00:00:00 2001 From: blitter Date: Tue, 27 Jun 2023 11:57:40 +0200 Subject: [PATCH 3/7] plans for next version --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 83bc343..458a25c 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,7 @@ These assumptions can be changed in the settings of the scheduled job. * [this tutorial where most parts of the script originate from](https://neverpanic.de/blog/2022/01/25/backing-up-your-android-phone-with-borgbackup/) * [this tutorial on how to parse command line arguments in bash](https://brianchildress.co/named-parameters-in-bash/) +* [termux cheat sheet](https://stephane-cheatsheets.readthedocs.io/en/latest/android/termux) # How to contribute, and planned changes @@ -317,6 +318,9 @@ When doing changes, please test that the following still works: * the `--BORGBACKUP_FORCE 1` argument works and overrides any circumstances normally prohibiting backups, regarding time, previous backups, and charging status * consider running [shellcheck](https://www.shellcheck.net/). Document all cases where whitespace is not allowed. +## Introduced since the last major version (version 1) + +* Documentation ## Upcoming breaking changes for version 2 @@ -333,12 +337,25 @@ Optional configuration: * directory to put marker files in (default: users home directory). Argument in client's config. +Reaction to errorneous configuration: + +* check for existence as first thing in every run: (and recommend ) + * secrets (nonempty) + * hostname + * matching client configuration + * host configuration for given secrets + +Documentation only: + +* how to make `termux-job-scheduler` log `stdout` + ## Features that are not planned yet, but maybe later -* human readable error messages when that config is not found or some options are not set * `--help` option that displays a useful overview * packing the script as a tmux [pkg](https://wiki.termux.com/wiki/Package_Management) * a [manpage](https://www.howtogeek.com/682871/how-to-create-a-man-page-on-linux/) * packing the script as an fdroid app * maybe passing some/all parameters (configuration options) as command line arguments instead of file contents +* send real notification upon backup +* send real notifaction when not been able to make make backup for ~10h -- GitLab From 1d4cad20192d761ba841554dcee0c7ecc8969cfe Mon Sep 17 00:00:00 2001 From: blitter Date: Tue, 27 Jun 2023 12:31:51 +0200 Subject: [PATCH 4/7] move to right path after execution --- backup.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backup.sh b/backup.sh index e825c90..52c0286 100644 --- a/backup.sh +++ b/backup.sh @@ -206,6 +206,16 @@ process_for_host() { fi } +#https://stackoverflow.com/a/630387 +#go to the path where this script is +MY_PATH="$(dirname -- "${BASH_SOURCE[0]}")" # relative +MY_PATH="$(cd -- "$MY_PATH" && pwd)" # absolutized and normalized +if [[ -z "$MY_PATH" ]] ; then + # error; for some reason, the path is not accessible + # to the script (e.g. permissions re-evaled after suid) + exit 1 # fail +fi + HOSTNAME=$(cat config/hostname) PWD_DIR="secrets/*" -- GitLab From 0920e3def423e5d33bd8f8bd8582c68e04ea4a40 Mon Sep 17 00:00:00 2001 From: blitter Date: Tue, 27 Jun 2023 12:34:01 +0200 Subject: [PATCH 5/7] goto new path --- backup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backup.sh b/backup.sh index 52c0286..1eaf2af 100644 --- a/backup.sh +++ b/backup.sh @@ -216,6 +216,8 @@ if [[ -z "$MY_PATH" ]] ; then exit 1 # fail fi +cd $MY_PATH + HOSTNAME=$(cat config/hostname) PWD_DIR="secrets/*" -- GitLab From 098de3e1c09e27354e61052d653d6a6425c7f76f Mon Sep 17 00:00:00 2001 From: blitter Date: Tue, 27 Jun 2023 12:48:43 +0200 Subject: [PATCH 6/7] no cd --- backup.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/backup.sh b/backup.sh index 1eaf2af..b8554fe 100644 --- a/backup.sh +++ b/backup.sh @@ -206,17 +206,6 @@ process_for_host() { fi } -#https://stackoverflow.com/a/630387 -#go to the path where this script is -MY_PATH="$(dirname -- "${BASH_SOURCE[0]}")" # relative -MY_PATH="$(cd -- "$MY_PATH" && pwd)" # absolutized and normalized -if [[ -z "$MY_PATH" ]] ; then - # error; for some reason, the path is not accessible - # to the script (e.g. permissions re-evaled after suid) - exit 1 # fail -fi - -cd $MY_PATH HOSTNAME=$(cat config/hostname) PWD_DIR="secrets/*" -- GitLab From 617082821c5e72a7852db7ff6fdf2274b3523fbc Mon Sep 17 00:00:00 2001 From: blitter Date: Tue, 27 Jun 2023 13:15:23 +0200 Subject: [PATCH 7/7] fixed for termux job --- README.md | 11 ++++------- backup.sh | 4 +++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 458a25c..d617041 100644 --- a/README.md +++ b/README.md @@ -139,8 +139,8 @@ The general idea is to put the `configuration` on all devices. There are multipl Create a symbolic link for both `config` and `secrets`. I recommend using a small setup script (that you could put into your config repo) for doing so: ```sh - ln -s config/ src/config - ln -s secrets/ src/secrets + ln -sr config/ src/config + ln -sr secrets/ src/secrets ``` Don't forgot to pull the submodule. Clone and pull with the option `--recurse-submodules`. Update the submodule from time to time (and update your config accordingly). @@ -201,7 +201,7 @@ The directory has to be the absolute path. (May begin with `~`.) You can create a `restart.sh` doing these steps automated. Execute it using `bash restart.sh`. ```sh -BACKUP_SCRIPT= +BACKUP_SCRIPT=~/production/tbo-config/src/backup.sh chmod u+x $BACKUP_SCRIPT @@ -345,13 +345,10 @@ Reaction to errorneous configuration: * matching client configuration * host configuration for given secrets -Documentation only: - -* how to make `termux-job-scheduler` log `stdout` - ## Features that are not planned yet, but maybe later +* maybe termux-tasker instead of termux-job-scheduler? * `--help` option that displays a useful overview * packing the script as a tmux [pkg](https://wiki.termux.com/wiki/Package_Management) * a [manpage](https://www.howtogeek.com/682871/how-to-create-a-man-page-on-linux/) diff --git a/backup.sh b/backup.sh index b8554fe..5521195 100644 --- a/backup.sh +++ b/backup.sh @@ -185,7 +185,6 @@ process_for_host() { fi rm -f ~/"${MARKER_START}"-* - touch "$MARKER_FILE" trap "cleanup" EXIT termux-wake-lock @@ -200,6 +199,9 @@ process_for_host() { err "Backup failed, aborting!" return 1 fi + + touch "$MARKER_FILE" #only touch this file when success! + if ! prune; then warn "Pruning failed. Continuing anyway." return 1 -- GitLab