-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexis
committed
Aug 17, 2024
1 parent
97e9f0c
commit 1695a6b
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
# Crontab example: 0 2 * * * /path/to/backup_script.sh >> /path/to/backup.log 2>&1 | ||
|
||
# Variables | ||
BACKUP_SRC="/home/ubuntu/CTFd-Plugins/data" | ||
BACKUP_DEST="/home/ubuntu/CTFd-Plugins/backups" # Feel free to move the backup folder to another location in order to have a real backup | ||
DOCKER_COMPOSE_PATH="/home/ubuntu/CTFd-Plugins/" | ||
BACKUP_COUNT=4 # Number of backups to keep | ||
TIMESTAMP=$(date +"%Y%m%d%H%M%S") | ||
BACKUP_NAME="backup_$TIMESTAMP.tar.gz" | ||
|
||
# Stop Docker stack | ||
echo "Stopping Docker stack..." | ||
cd $DOCKER_COMPOSE_PATH | ||
docker compose stop | ||
|
||
# Create backup | ||
echo "Creating backup of $BACKUP_SRC..." | ||
mkdir -p $BACKUP_DEST | ||
tar -czf $BACKUP_DEST/$BACKUP_NAME $BACKUP_SRC | ||
|
||
# Remove old backups | ||
echo "Removing old backups, keeping the latest $BACKUP_COUNT..." | ||
cd $BACKUP_DEST | ||
ls -1tr | head -n -$BACKUP_COUNT | xargs -d '\n' rm -f -- | ||
|
||
cd $DOCKER_COMPOSE_PATH | ||
docker compose start | ||
|
||
echo "Backup completed successfully." |