From 31028465fa55950f364c84dd75d00e08ea37743f Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Fri, 20 Jun 2025 17:04:57 +0200 Subject: [PATCH 1/2] Improve plot update script --- README.md | 29 ++++++++++++++++++++++++++--- scripts/update_plots.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100755 scripts/update_plots.sh diff --git a/README.md b/README.md index 5fbef0d..7b4da05 100644 --- a/README.md +++ b/README.md @@ -42,15 +42,17 @@ in MongoDB. ## MongoDB backup script -`scripts/backup_mongodb.sh` dumps a MongoDB database to a Dropbox-synced -folder. The script starts `mongod` if it is not running and stops it again -when the backup finishes (if it was started by the script). +`scripts/backup_mongodb.sh` dumps a MongoDB database and creates a compressed +`db_backup_YYYY-MM-DD.tar.gz` file in a Dropbox-synced folder. The script +starts `mongod` if it is not running and stops it again when the backup +finishes (if it was started by the script). Make it executable before scheduling it with `cron`: ```bash chmod +x scripts/backup_mongodb.sh ``` + Store `DBNAME` (and optional credentials) in environment variables rather than editing the script. You may create a file named `~/.mongodb_backup_env` with content like: @@ -62,3 +64,24 @@ export DBNAME="fmriprep_stats" ``` The backup script will source this file if present. + +## Weekly plot update script + +`scripts/update_plots.sh` generates plots with `src/run.py plot` and pushes them +to a clone of the `nipreps.github.io` website. The path to that clone can be +given as an argument and defaults to `$HOME/workspace/nipreps.github.io`. +The script may be run from any directory and validates that the target is a Git +repository. + +Make the script executable: + +```bash +chmod +x scripts/update_plots.sh +``` + +To run it every Monday at 5 AM, add this line to your crontab: + +``` +0 5 * * 1 /path/to/fmriprep_stats/scripts/update_plots.sh >>/tmp/update_plots.log 2>&1 +``` + diff --git a/scripts/update_plots.sh b/scripts/update_plots.sh new file mode 100755 index 0000000..78b3254 --- /dev/null +++ b/scripts/update_plots.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# scripts/update_plots.sh +# Generate weekly plots and push them to the nipreps.github.io repository. + +set -euo pipefail + +REPO_DIR="${1:-$HOME/workspace/nipreps.github.io}" +ASSETS_DIR="$REPO_DIR/docs/assets" + +if [ ! -d "$REPO_DIR/.git" ]; then + echo "Error: $REPO_DIR is not a git repository" >&2 + exit 1 +fi + +mkdir -p "$ASSETS_DIR" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR/.." + +python src/run.py plot -o "$ASSETS_DIR" + +cd "$REPO_DIR" +git pull --ff-only +git add docs/assets +if ! git diff --cached --quiet; then + git commit -m "Update stats plots" + git push +else + echo "No changes to commit." +fi + From 859f32bb6ce3a5ccde31613fd42a4330abda1f9c Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Fri, 20 Jun 2025 17:13:54 +0200 Subject: [PATCH 2/2] enh: improve readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b4da05..1f9e296 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,6 @@ chmod +x scripts/update_plots.sh To run it every Monday at 5 AM, add this line to your crontab: ``` -0 5 * * 1 /path/to/fmriprep_stats/scripts/update_plots.sh >>/tmp/update_plots.log 2>&1 +0 5 * * 1 /path/to/fmriprep_stats/scripts/update_plots.sh 2>> $HOME/var/logs/update_plots.err >> $HOME/var/logs/update_plots.log ```