Skip to content

Commit

Permalink
Add backup script for mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Aug 28, 2022
1 parent f236ea6 commit dcf0fe5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions faf-extra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ services:
env_file: ./config/extra/mongodb/mongodb.env
volumes:
- ./data/mongodb/data/db:/data/db
# Mongodump is corrupting the backup file when piping out via stdout
- ./data/mongodb/backup:/backup

#
# Forum software
Expand Down
2 changes: 1 addition & 1 deletion scripts/backup-faf-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mv $DB_BACKUP/04 $DB_BACKUP/05
mv $DB_BACKUP/03 $DB_BACKUP/04
mv $DB_BACKUP/02 $DB_BACKUP/03
mv $DB_BACKUP/01 $DB_BACKUP/02
mkdir $DB_BACKUP/01
mkdir -p $DB_BACKUP/01

echo "* Creating backup..."
echo "------------------------"
Expand Down
27 changes: 27 additions & 0 deletions scripts/backup-mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# This scripts creates a rotating backup of the last 7 days.
# Subfolder 01 contains the newewst, subfolder 07 the latest backup.

# modify the following to suit your environment
source /opt/faf/config/extra/mongodb/mongodb.env
export DB_BACKUP="/opt/faf/backups/mongodb"

echo "*** MongoDB backup"
echo "* Rotate existing backups"
echo "------------------------"

rm -rf $DB_BACKUP/07
mv $DB_BACKUP/06 $DB_BACKUP/07
mv $DB_BACKUP/05 $DB_BACKUP/06
mv $DB_BACKUP/04 $DB_BACKUP/05
mv $DB_BACKUP/03 $DB_BACKUP/04
mv $DB_BACKUP/02 $DB_BACKUP/03
mv $DB_BACKUP/01 $DB_BACKUP/02
mkdir -p $DB_BACKUP/01

echo "* Creating backup..."
echo "------------------------"
docker-compose --compatibility --project-directory /opt/faf -f /opt/faf/faf-extra.yml exec mongodb mongodump -u "$MONGO_NODEBB_USERNAME" -p "$MONGO_NODEBB_PASSWORD" -d "$MONGO_NODEBB_DATABASE" --archive=/backup/archive.gz --gzip
mv ./data/mongodb/backup/archive.gz "$DB_BACKUP/01/$(date +"%Y-%m-%d-%H-%M-%S").gz"
echo "Done"
exit 0

0 comments on commit dcf0fe5

Please sign in to comment.