Files
BrainKP/scripts/backup-apps.sh
T

45 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Backup /root/Apps → Google Drive (Apps)
set -e
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/tmp/backup-apps"
DEST="gdrive:Apps"
echo "[$(date)] Backup Apps started"
# Cleanup old temp
rm -rf "$BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
# Loop over all directories in /root/Apps/
cd /root/Apps
for APP_DIR in */; do
# Remove trailing slash
APP_NAME=${APP_DIR%/}
# Skip if it's not a directory or if it is the backup-ui/BrainKP itself (to prevent recursion/lock if needed, though they are fine)
[ -d "$APP_NAME" ] || continue
echo "Backing up app: $APP_NAME"
# Compress each app into its own tar.gz file, excluding heavy unnecessary folders
tar -czf "$BACKUP_DIR/${APP_NAME}-$DATE.tar.gz" \
--exclude="node_modules" \
--exclude="venv" \
--exclude=".venv" \
--exclude="__pycache__" \
"$APP_NAME" 2>/dev/null || true
done
# Sync to Google Drive
rclone copy "$BACKUP_DIR" "$DEST" --progress
# Keep only last 7 days in GDrive
rclone delete "$DEST" --min-age 7d
# Cleanup local
rm -rf "$BACKUP_DIR"
echo "[$(date)] Backup Apps finished"