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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@ python src/run.py plot

will generate the performance and version stream plots using the records stored
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).

Make it executable before scheduling it with `cron`:

```bash
chmod +x scripts/backup_mongodb.sh
```
41 changes: 41 additions & 0 deletions scripts/backup_mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# scripts/backup_mongodb.sh
# Backup MongoDB database, ensuring mongod is running.

DATE=$(date +%Y-%m-%d)
BACKUP_DIR="$HOME/Dropbox/backups"
DBNAME="DBNAME"
USERNAME="USERNAME"
PASSWORD="PASSWORD"
BACKUP_PATH="$BACKUP_DIR/db_backup_${DATE}"

mkdir -p "$BACKUP_DIR"

# Track whether we started mongod
started_mongod=false

# Check if mongod process is running
if pgrep mongod >/dev/null; then
echo "mongod is running"
else
echo "mongod is not running. Starting..."
if command -v systemctl >/dev/null; then
sudo systemctl start mongod
else
sudo service mongod start
fi
started_mongod=true
fi

# Dump the database
mongodump --db "$DBNAME" --username "$USERNAME" --password "$PASSWORD" --out "$BACKUP_PATH"

# Stop mongod if we started it
if [ "$started_mongod" = true ]; then
echo "Stopping mongod..."
if command -v systemctl >/dev/null; then
sudo systemctl stop mongod
else
sudo service mongod stop
fi
fi