n8n / backup.sh
tryapp's picture
Upload 5 files
5064fae verified
Raw History Blame Contribute Delete
1.02 kB
#!/bin/bash
INTERVAL="${BACKUP_INTERVAL:-300}"
BACKUP_DIR="/data/backups"
DUMP_FILE="$BACKUP_DIR/n8n_backup.sql"
mkdir -p "$BACKUP_DIR"
sleep 60
while true; do
if su - postgres -c "pg_isready -h localhost -p 5432" > /dev/null 2>&1; then
su - postgres -c "pg_dump -d n8n" > "$DUMP_FILE.tmp" 2>/dev/null
if [ $? -eq 0 ] && [ -s "$DUMP_FILE.tmp" ]; then
mv "$DUMP_FILE.tmp" "$DUMP_FILE"
if [ -n "$HF_TOKEN" ] && [ -n "$HF_BACKUP_REPO" ]; then
python3 -c "
from huggingface_hub import HfApi
api = HfApi(token='$HF_TOKEN')
try:
api.create_repo(repo_id='$HF_BACKUP_REPO', repo_type='dataset', private=True, exist_ok=True)
api.upload_file(path_or_fileobj='$DUMP_FILE', path_in_repo='n8n_backup.sql', repo_id='$HF_BACKUP_REPO', repo_type='dataset', token='$HF_TOKEN')
except Exception as e:
print(f'Backup upload failed: {e}')
" 2>/dev/null
fi
else
rm -f "$DUMP_FILE.tmp"
fi
fi
sleep "$INTERVAL"
done