Skip to content

Commit 3102846

Browse files
committed
Improve plot update script
1 parent a53eeee commit 3102846

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ in MongoDB.
4242

4343
## MongoDB backup script
4444

45-
`scripts/backup_mongodb.sh` dumps a MongoDB database to a Dropbox-synced
46-
folder. The script starts `mongod` if it is not running and stops it again
47-
when the backup finishes (if it was started by the script).
45+
`scripts/backup_mongodb.sh` dumps a MongoDB database and creates a compressed
46+
`db_backup_YYYY-MM-DD.tar.gz` file in a Dropbox-synced folder. The script
47+
starts `mongod` if it is not running and stops it again when the backup
48+
finishes (if it was started by the script).
4849

4950
Make it executable before scheduling it with `cron`:
5051

5152
```bash
5253
chmod +x scripts/backup_mongodb.sh
5354
```
55+
5456
Store `DBNAME` (and optional credentials) in environment variables rather than
5557
editing the script. You may create a file named `~/.mongodb_backup_env` with
5658
content like:
@@ -62,3 +64,24 @@ export DBNAME="fmriprep_stats"
6264
```
6365

6466
The backup script will source this file if present.
67+
68+
## Weekly plot update script
69+
70+
`scripts/update_plots.sh` generates plots with `src/run.py plot` and pushes them
71+
to a clone of the `nipreps.github.io` website. The path to that clone can be
72+
given as an argument and defaults to `$HOME/workspace/nipreps.github.io`.
73+
The script may be run from any directory and validates that the target is a Git
74+
repository.
75+
76+
Make the script executable:
77+
78+
```bash
79+
chmod +x scripts/update_plots.sh
80+
```
81+
82+
To run it every Monday at 5 AM, add this line to your crontab:
83+
84+
```
85+
0 5 * * 1 /path/to/fmriprep_stats/scripts/update_plots.sh >>/tmp/update_plots.log 2>&1
86+
```
87+

scripts/update_plots.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# scripts/update_plots.sh
3+
# Generate weekly plots and push them to the nipreps.github.io repository.
4+
5+
set -euo pipefail
6+
7+
REPO_DIR="${1:-$HOME/workspace/nipreps.github.io}"
8+
ASSETS_DIR="$REPO_DIR/docs/assets"
9+
10+
if [ ! -d "$REPO_DIR/.git" ]; then
11+
echo "Error: $REPO_DIR is not a git repository" >&2
12+
exit 1
13+
fi
14+
15+
mkdir -p "$ASSETS_DIR"
16+
17+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18+
cd "$SCRIPT_DIR/.."
19+
20+
python src/run.py plot -o "$ASSETS_DIR"
21+
22+
cd "$REPO_DIR"
23+
git pull --ff-only
24+
git add docs/assets
25+
if ! git diff --cached --quiet; then
26+
git commit -m "Update stats plots"
27+
git push
28+
else
29+
echo "No changes to commit."
30+
fi
31+

0 commit comments

Comments
 (0)