feat(deploy): add MySQL backup script (daily cron, 14-day retention)
Installed in CT 244 at /opt/forwarder/backup-mysql.sh with /etc/cron.d/forwarder-backup running at 03:00 UTC daily. Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1 parent
7100440294
commit
34f7fd9cdd
1 file changed
+14
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
BACKUP_DIR=/opt/forwarder/backups
|
||||
KEEP_DAYS=14
|
||||
TS=$(date +%Y%m%d_%H%M%S)
|
||||
FILE="$BACKUP_DIR/forwarder_${TS}.sql.gz"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
set -a; source /opt/forwarder/.env; set +a
|
||||
docker exec forwarder-mysql-1 \
|
||||
mysqldump --no-tablespaces -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" \
|
||||
| gzip > "$FILE"
|
||||
SIZE=$(du -h "$FILE" | cut -f1)
|
||||
echo "Backup: $FILE ($SIZE)"
|
||||
find "$BACKUP_DIR" -name "forwarder_*.sql.gz" -mtime +$KEEP_DAYS -delete
|
||||
Reference in new issue
Block a user