Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 2>> $HOME/var/logs/update_plots.err >> $HOME/var/logs/update_plots.log
```

31 changes: 31 additions & 0 deletions scripts/update_plots.sh
Original file line number Diff line number Diff line change
@@ -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