Add Seafile backup script with Zabbix monitoring
- backup.sh: mysqldump all 3 DBs + rsync seafile-data, runs every 3 days via root crontab, keeps last 5 backups in /mnt/backups/seafile - Notifies Zabbix trapper item seafile.backup.ts (id 70369) on AgapHost Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
44
seafile/backup.sh
Executable file
44
seafile/backup.sh
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Seafile backup script.
|
||||||
|
# Backs up MySQL databases and seafile data directory.
|
||||||
|
# Runs every 3 days via root crontab. Keeps last 5 backups.
|
||||||
|
# Notifies Zabbix (item seafile.backup.ts, id 70369 on AgapHost) after success.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
BACKUP_DIR="/mnt/backups/seafile"
|
||||||
|
DATA_DIR="/mnt/misc/seafile"
|
||||||
|
DATE=$(date '+%Y%m%d-%H%M')
|
||||||
|
DEST="$BACKUP_DIR/$DATE"
|
||||||
|
|
||||||
|
mkdir -p "$DEST"
|
||||||
|
|
||||||
|
# Dump all three Seafile databases from the running container
|
||||||
|
for DB in ccnet_db seafile_db seahub_db; do
|
||||||
|
docker exec seafile-mysql mysqldump \
|
||||||
|
-u seafile -pFWsYYeZa15ro6x \
|
||||||
|
--single-transaction "$DB" > "$DEST/${DB}.sql"
|
||||||
|
echo "Dumped: $DB"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Copy seafile data (libraries, config — excludes mysql and caddy dirs)
|
||||||
|
rsync -a --delete \
|
||||||
|
--exclude='seafile-mysql/' \
|
||||||
|
--exclude='seafile-caddy/' \
|
||||||
|
"$DATA_DIR/" "$DEST/data/"
|
||||||
|
|
||||||
|
echo "$(date): Backup complete: $DEST"
|
||||||
|
ls "$DEST/"
|
||||||
|
|
||||||
|
# Notify Zabbix
|
||||||
|
if [[ -f /root/.zabbix_token ]]; then
|
||||||
|
ZABBIX_TOKEN=$(cat /root/.zabbix_token)
|
||||||
|
curl -s -X POST http://localhost:81/api_jsonrpc.php \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $ZABBIX_TOKEN" \
|
||||||
|
-d "{\"jsonrpc\":\"2.0\",\"method\":\"history.push\",\"id\":1,\"params\":{\"itemid\":\"70369\",\"value\":\"$(date '+%Y-%m-%d %H:%M')\"}}" > /dev/null \
|
||||||
|
&& echo "Zabbix notified."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Rotate: keep last 5 backups
|
||||||
|
ls -1dt "$BACKUP_DIR"/[0-9]*-[0-9]* 2>/dev/null | tail -n +6 | xargs -r rm -rf
|
||||||
Reference in New Issue
Block a user