mirror of
https://github.com/myronblair/jarvis
synced 2026-07-28 08:43:00 -05:00
jarvis-backup.sh: was DB-only, now also backs up /var/www/jarvis, /opt/jarvis-arc, nginx site config, systemd unit, and root crontab — a DB dump alone was useless without the app code and daemon needed to actually restore JARVIS. Also fixed a typo (SIYE->SIZE) that silently broke the backup-size log line.
This commit is contained in:
+14
-3
@@ -1,5 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# JARVIS backup — DB dump as tar.gz, admin-panel compatible
|
# JARVIS backup — DB dump + all files needed to actually restore JARVIS, as tar.gz
|
||||||
|
# Fixed 2026-07-07: this only ever backed up the MySQL database. If this VM were
|
||||||
|
# lost, the DB alone is useless without the application code, the reactor daemon,
|
||||||
|
# its systemd unit, and the nginx site config — none of which were captured. Also
|
||||||
|
# fixed a typo ($SIYE -> $SIZE) that silently broke the size line in the log.
|
||||||
BACKUP_DIR="/var/backups/jarvis"
|
BACKUP_DIR="/var/backups/jarvis"
|
||||||
LOG="$BACKUP_DIR/backup.log"
|
LOG="$BACKUP_DIR/backup.log"
|
||||||
LOCK="$BACKUP_DIR/backup.lock"
|
LOCK="$BACKUP_DIR/backup.lock"
|
||||||
@@ -18,9 +22,16 @@ cleanup() { rm -rf "$TMPDIR"; rm -f "$LOCK"; }
|
|||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
if mysqldump -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$TMPDIR/jarvis_db.sql" 2>>"$LOG"; then
|
if mysqldump -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$TMPDIR/jarvis_db.sql" 2>>"$LOG"; then
|
||||||
tar -czf "$OUTFILE" -C "$TMPDIR" jarvis_db.sql
|
mkdir -p "$TMPDIR/files/etc"
|
||||||
|
cp -a /var/www/jarvis "$TMPDIR/files/var-www-jarvis"
|
||||||
|
cp -a /opt/jarvis-arc "$TMPDIR/files/opt-jarvis-arc"
|
||||||
|
cp -a /etc/nginx/sites-enabled/jarvis "$TMPDIR/files/etc/nginx-site-jarvis" 2>>"$LOG"
|
||||||
|
cp -a /etc/systemd/system/jarvis-arc.service "$TMPDIR/files/etc/jarvis-arc.service" 2>>"$LOG"
|
||||||
|
crontab -l > "$TMPDIR/files/etc/root-crontab.txt" 2>>"$LOG"
|
||||||
|
|
||||||
|
tar -czf "$OUTFILE" -C "$TMPDIR" jarvis_db.sql files
|
||||||
SIZE=$(du -sh "$OUTFILE" | cut -f1)
|
SIZE=$(du -sh "$OUTFILE" | cut -f1)
|
||||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Backup OK: $(basename "$OUTFILE") ($SIYE)" >> "$LOG"
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Backup OK: $(basename "$OUTFILE") ($SIZE)" >> "$LOG"
|
||||||
else
|
else
|
||||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: mysqldump failed" >> "$LOG"
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: mysqldump failed" >> "$LOG"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user