Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feature: add backups storage provider

Piyaf0e640237a76
diff --git a/CLAUDE.md b/CLAUDE.md
index fd074f19..b48f0c6e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1,114 +1,7 @@
-# CLAUDE.md
+---
+description:
+alwaysApply: true
+---
-This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
-
-## Project Overview
-
-ServerKit is a server control panel for managing web applications, databases, Docker containers, and security on VPS/dedicated servers. Flask backend (Python 3.11+), React frontend (Vite + LESS), SQLite/PostgreSQL database, real-time updates via Socket.IO.
-
-## Development Commands
-
-```bash
-# Backend (port 5000, hot-reload)
-cd backend && python -m venv venv && source venv/bin/activate # Windows: venv\Scripts\activate
-pip install -r requirements.txt
-python run.py
-
-# Frontend (port 5173, Vite HMR)
-cd frontend && npm install && npm run dev
-
-# Both at once (Linux/WSL)
-./scripts/dev/start.sh
-
-# Frontend lint
-cd frontend && npm run lint
-
-# Frontend production build
-cd frontend && npm run build
-
-# Backend tests
-cd backend && pytest
-cd backend && pytest --cov=app
-
-# Docker
-docker compose -f docker-compose.dev.yml up --build
-```
-
-Default dev credentials: `admin` / `admin`
-
-## Architecture
-
-### Backend (`backend/`)
-
-Flask app factory in `app/__init__.py` using `create_app()`. Three-layer architecture:
-
-- **`app/api/`** — Flask Blueprints, one file per feature (36 files). All routes prefixed `/api/v1/`. JWT-protected via `@jwt_required()`.
-- **`app/services/`** — Business logic (48 files). Services are stateless modules called by API routes. Heavy lifting (shell commands, Docker API, file operations) happens here.
-- **`app/models/`** — SQLAlchemy ORM models (15 files). Tables auto-created on startup via `db.create_all()`.
-
-Other backend components:
-- `app/sockets.py` — Socket.IO event handlers for real-time metrics, logs, terminal
-- `app/agent_gateway.py` — Multi-server agent communication
-- `app/middleware/security.py` — Security headers middleware
-- `config.py` — Environment-based config (development/production/testing)
-- `run.py` — Entry point
-
-### Frontend (`frontend/src/`)
-
-React 18 SPA with client-side routing:
-
-- **`pages/`** — Route-level components (~29 files). Each maps to a route in `App.jsx`.
-- **`components/`** — Reusable UI components shared across pages.
-- **`contexts/`** — React Context providers: `AuthContext` (JWT auth + token refresh), `ThemeContext`, `ToastContext`, `ResourceTierContext` (feature gating).
-- **`services/api.js`** — Centralized `ApiService` class handling all HTTP requests, token management, and auto-refresh.
-- **`hooks/`** — Custom React hooks for reusable logic.
-- **`styles/`** — LESS stylesheets with design system variables. Main entry is `main.less`. Page-specific styles in `styles/pages/`.
-- **`layouts/`** — `DashboardLayout` wraps authenticated pages (sidebar + header).
-
-Route guards: `PrivateRoute` (auth check), `PublicRoute` (redirect if logged in), `SetupRoute` (redirect to `/setup` if not configured).
-
-### Request Flow
-
-Browser → Nginx (`:80`/`:443`) → proxy_pass to Docker containers (`:8001-8999`) for managed apps, or to Flask (`:5000`) for the panel API. The 404 handler in Flask serves `index.html` for SPA client-side routing; API routes return JSON errors.
-
-### Production Build
-
-The Dockerfile is multi-stage: Node 20 builds frontend, Python 3.11 serves everything via Gunicorn with GeventWebSocket workers. Built frontend is served from Flask's static folder.
-
-## Code Style
-
-### Python
-- PEP 8, type hints where helpful
-- Service functions are standalone (no classes unless stateful)
-- Consistent JSON error responses: `{'error': 'message'}, status_code`
-
-### React/JavaScript
-- Functional components with hooks only
-- PascalCase for components (`Sidebar.jsx`), camelCase for everything else
-- LESS for styling — use existing design system variables (`@card-bg`, `@primary-color`, `@spacing-md`, etc.) and BEM-like naming (`.block__element--modifier`)
-- Context API for global state; props drilling is fine for 2-3 levels
-- No inline styles; no Tailwind/CSS-in-JS
-
-### Diffs & Commits
-- One logical change per commit
-- Minimal, focused diffs — don't silently refactor surrounding code
-- Branch naming: `feature/`, `fix/`, `docs/`, `refactor/` prefixes
-
-## Adding a New Feature (Full Stack)
-
-1. **Model**: Add SQLAlchemy model in `backend/app/models/`
-2. **Service**: Add business logic in `backend/app/services/`
-3. **API**: Create Blueprint in `backend/app/api/`, register it in `app/__init__.py` with `url_prefix='/api/v1/<feature>'`
-4. **Frontend API**: Add methods to `ApiService` in `frontend/src/services/api.js`
-5. **Page**: Create page component in `frontend/src/pages/`, add route in `App.jsx`
-6. **Styles**: Add LESS file in `frontend/src/styles/pages/`, import in `main.less`
-
-## Key Environment Variables
-
-| Variable | Purpose |
-|----------|---------|
-| `SECRET_KEY` | Flask session signing |
-| `JWT_SECRET_KEY` | JWT token signing |
-| `DATABASE_URL` | DB connection string (`sqlite:///...` or PostgreSQL) |
-| `CORS_ORIGINS` | Comma-separated allowed origins |
-| `FLASK_ENV` | `development` or `production` |
+Never allow pushing if branch type does not match change type.
+Be strict. Do not be permissive.
diff --git a/ROADMAP.md b/ROADMAP.md
index 3f28a025..f91f8e43 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -151,18 +151,18 @@ This document outlines the development roadmap for ServerKit. Features are organ
---
-## Phase 12: Backup & Restore (Planned)
+## Phase 12: Backup & Restore (Completed)
**Priority: High**
-- [ ] Automated database backups
-- [ ] File/directory backups
-- [ ] S3-compatible storage support
-- [ ] Backblaze B2 integration
-- [ ] Backup scheduling
-- [ ] One-click restore
-- [ ] Backup retention policies
-- [ ] Offsite backup verification
+- [x] Automated database backups
+- [x] File/directory backups
+- [x] S3-compatible storage support
+- [x] Backblaze B2 integration
+- [x] Backup scheduling
+- [x] One-click restore
+- [x] Backup retention policies
+- [x] Offsite backup verification
---
diff --git a/backend/.gitignore b/backend/.gitignore
index 8de61ab2..7c95d7f4 100644
--- a/backend/.gitignore
+++ b/backend/.gitignore
@@ -5,8 +5,19 @@ __pycache__/
*.so
.Python
venv/
+.venv/
env/
ENV/
+.env.local
+.env.*.local
+*.key
+*.pem
+*.crt
+*.csr
+*.key
+*.pem
+*.crt
+*.csr
# Database
*.db
diff --git a/backend/app/api/backups.py b/backend/app/api/backups.py
index b6ea26b3..b59ed735 100644
--- a/backend/app/api/backups.py
+++ b/backend/app/api/backups.py
@@ -3,6 +3,7 @@ from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import User, Application
from app.services.backup_service import BackupService
+from app.services.storage_provider_service import StorageProviderService
from app import paths
backups_bp = Blueprint('backups', __name__)
@@ -117,6 +118,28 @@ def backup_database():
return jsonify(result), 201 if result['success'] else 400
+@backups_bp.route('/files', methods=['POST'])
+@jwt_required()
+@admin_required
+def backup_files():
+ """Backup specific files and directories."""
+ data = request.get_json()
+
+ if not data:
+ return jsonify({'error': 'No data provided'}), 400
+
+ file_paths = data.get('paths', [])
+ if not file_paths:
+ return jsonify({'error': 'paths is required (list of file/directory paths)'}), 400
+
+ result = BackupService.backup_files(
+ file_paths=file_paths,
+ backup_name=data.get('name')
+ )
+
+ return jsonify(result), 201 if result['success'] else 400
+
+
@backups_bp.route('/restore/application', methods=['POST'])
@jwt_required()
@admin_required
@@ -185,7 +208,8 @@ def cleanup_backups():
return jsonify(result), 200 if result['success'] else 400
-# Schedules
+# --- Schedules ---
+
@backups_bp.route('/schedules', methods=['GET'])
@jwt_required()
@admin_required
@@ -215,12 +239,26 @@ def add_schedule():
backup_type=data['backup_type'],
target=data['target'],
schedule_time=data['schedule_time'],
- days=data.get('days')
+ days=data.get('days'),
+ upload_remote=data.get('upload_remote', False)
)
return jsonify(result), 201 if result['success'] else 400
+@backups_bp.route('/schedules/<schedule_id>', methods=['PUT'])
+@jwt_required()
+@admin_required
+def update_schedule(schedule_id):
+ """Update a backup schedule."""
+ data = request.get_json()
+ if not data:
+ return jsonify({'error': 'No data provided'}), 400
+
+ result = BackupService.update_schedule(schedule_id, data)
+ return jsonify(result), 200 if result.get('success') else 400
+
+
@backups_bp.route('/schedules/<schedule_id>', methods=['DELETE'])
@jwt_required()
@admin_required
@@ -228,3 +266,118 @@ def remove_schedule(schedule_id):
"""Remove a backup schedule."""
result = BackupService.remove_schedule(schedule_id)
return jsonify(result), 200 if result['success'] else 400
+
+
+# --- Remote Storage ---
+
+@backups_bp.route('/storage', methods=['GET'])
+@jwt_required()
+@admin_required
+def get_storage_config():
+ """Get storage provider configuration (secrets masked)."""
+ config = StorageProviderService.get_config_masked()
+ return jsonify(config), 200
+
+
+@backups_bp.route('/storage', methods=['PUT'])
+@jwt_required()
+@admin_required
+def update_storage_config():
+ """Update storage provider configuration."""
+ data = request.get_json()
+ if not data:
+ return jsonify({'error': 'No data provided'}), 400
+
+ result = StorageProviderService.save_config(data)
+ return jsonify(result), 200 if result['success'] else 400
+
+
+@backups_bp.route('/storage/test', methods=['POST'])
+@jwt_required()
+@admin_required
+def test_storage_connection():
+ """Test connection to storage provider."""
+ data = request.get_json()
+ # Use provided config for testing, or current saved config
+ config = data if data else None
+ result = StorageProviderService.test_connection(config)
+ return jsonify(result), 200 if result['success'] else 400
+
+
+@backups_bp.route('/upload', methods=['POST'])
+@jwt_required()
+@admin_required
+def upload_to_remote():
+ """Upload a local backup to remote storage."""
+ data = request.get_json()
+ if not data or 'backup_path' not in data:
+ return jsonify({'error': 'backup_path is required'}), 400
+
+ backup_path = data['backup_path']
+
+ if not backup_path.startswith(paths.SERVERKIT_BACKUP_DIR):
+ return jsonify({'error': 'Invalid backup path'}), 400
+
+ if os.path.isdir(backup_path):
+ result = StorageProviderService.upload_directory(backup_path)
+ elif os.path.isfile(backup_path):
+ result = StorageProviderService.upload_file(backup_path)
+ else:
+ return jsonify({'error': 'Backup not found'}), 404
+
+ return jsonify(result), 200 if result['success'] else 400
+
+
+@backups_bp.route('/verify', methods=['POST'])
+@jwt_required()
+@admin_required
+def verify_remote_backup():
+ """Verify a backup exists and matches on remote storage."""
+ data = request.get_json()
+ if not data:
+ return jsonify({'error': 'No data provided'}), 400
+
+ remote_key = data.get('remote_key')
+ local_path = data.get('local_path')
+
+ if not remote_key or not local_path:
+ return jsonify({'error': 'remote_key and local_path are required'}), 400
+
+ result = StorageProviderService.verify_file(remote_key, local_path)
+ return jsonify(result), 200
+
+
+@backups_bp.route('/remote', methods=['GET'])
+@jwt_required()
+@admin_required
+def list_remote_backups():
+ """List backups on remote storage."""
+ prefix = request.args.get('prefix')
+ result = StorageProviderService.list_files(prefix)
+ return jsonify(result), 200 if result['success'] else 400
+
+
+@backups_bp.route('/remote/download', methods=['POST'])
+@jwt_required()
+@admin_required
+def download_from_remote():
+ """Download a backup from remote storage to local."""
+ data = request.get_json()
+ if not data or 'remote_key' not in data:
+ return jsonify({'error': 'remote_key is required'}), 400
+
+ remote_key = data['remote_key']
+ # Determine local path from remote key
+ local_path = data.get('local_path')
+ if not local_path:
+ # Strip prefix and save to backup dir
+ key_parts = remote_key.split('/')
+ # Remove the prefix path component
+ filename = '/'.join(key_parts[1:]) if len(key_parts) > 1 else key_parts[0]
+ local_path = os.path.join(paths.SERVERKIT_BACKUP_DIR, filename)
+
+ if not local_path.startswith(paths.SERVERKIT_BACKUP_DIR):
+ return jsonify({'error': 'Download path must be within backup directory'}), 400
+
+ result = StorageProviderService.download_file(remote_key, local_path)
+ return jsonify(result), 200 if result['success'] else 400
diff --git a/backend/app/services/backup_service.py b/backend/app/services/backup_service.py
index a96542b6..a8a2bece 100644
--- a/backend/app/services/backup_service.py
+++ b/backend/app/services/backup_service.py
@@ -25,6 +25,7 @@ class BackupService:
TYPE_APP = 'application'
TYPE_DATABASE = 'database'
TYPE_FULL = 'full'
+ TYPE_FILES = 'files'
_scheduler_thread = None
_stop_scheduler = False
@@ -39,7 +40,7 @@ class BackupService:
@classmethod
def ensure_backup_dirs(cls) -> None:
"""Ensure backup directories exist."""
- for subdir in ['applications', 'databases', 'full', 'scheduled']:
+ for subdir in ['applications', 'databases', 'full', 'scheduled', 'files']:
path = os.path.join(cls.BACKUP_BASE_DIR, subdir)
os.makedirs(path, exist_ok=True)
@@ -99,7 +100,8 @@ class BackupService:
'timestamp': datetime.now().isoformat(),
'type': cls.TYPE_APP,
'files_backup': files_backup,
- 'size': os.path.getsize(files_backup)
+ 'size': os.path.getsize(files_backup),
+ 'remote_status': 'local'
}
# Backup database if requested
@@ -119,6 +121,9 @@ class BackupService:
with open(meta_path, 'w') as f:
json.dump(backup_info, f, indent=2)
+ # Auto-upload to remote if configured
+ cls._auto_upload(backup_dir, backup_info)
+
return {
'success': True,
'backup': backup_info,
@@ -202,21 +207,84 @@ class BackupService:
if result.get('success'):
# Rename to final path
os.rename(result['path'], backup_path)
+
+ backup_info = {
+ 'name': backup_name,
+ 'path': backup_path,
+ 'timestamp': datetime.now().isoformat(),
+ 'type': cls.TYPE_DATABASE,
+ 'database_type': db_type,
+ 'database_name': db_name,
+ 'size': os.path.getsize(backup_path),
+ 'remote_status': 'local'
+ }
+
+ # Auto-upload to remote if configured
+ cls._auto_upload(backup_path, backup_info)
+
return {
'success': True,
- 'backup': {
- 'name': backup_name,
- 'path': backup_path,
- 'timestamp': datetime.now().isoformat(),
- 'type': cls.TYPE_DATABASE,
- 'database_type': db_type,
- 'database_name': db_name,
- 'size': os.path.getsize(backup_path)
- }
+ 'backup': backup_info
}
return result
+ @classmethod
+ def backup_files(cls, file_paths: List[str], backup_name: str = None) -> Dict:
+ """Backup specific files and directories."""
+ cls.ensure_backup_dirs()
+
+ # Validate paths
+ valid_paths = []
+ for p in file_paths:
+ if os.path.exists(p):
+ valid_paths.append(p)
+
+ if not valid_paths:
+ return {'success': False, 'error': 'No valid file paths provided'}
+
+ timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
+ if not backup_name:
+ backup_name = f"files_{timestamp}"
+ else:
+ backup_name = f"{backup_name}_{timestamp}"
+
+ backup_file = os.path.join(cls.BACKUP_BASE_DIR, 'files', f'{backup_name}.tar.gz')
+
+ try:
+ with tarfile.open(backup_file, 'w:gz') as tar:
+ for p in valid_paths:
+ tar.add(p, arcname=os.path.basename(p))
+
+ backup_info = {
+ 'name': f'{backup_name}.tar.gz',
+ 'path': backup_file,
+ 'timestamp': datetime.now().isoformat(),
+ 'type': cls.TYPE_FILES,
+ 'source_paths': valid_paths,
+ 'size': os.path.getsize(backup_file),
+ 'remote_status': 'local'
+ }
+
+ # Save metadata alongside the archive
+ meta_path = os.path.join(cls.BACKUP_BASE_DIR, 'files', f'{backup_name}.json')
+ with open(meta_path, 'w') as f:
+ json.dump(backup_info, f, indent=2)
+
+ # Auto-upload to remote if configured
+ cls._auto_upload(backup_file, backup_info)
+
+ return {
+ 'success': True,
+ 'backup': backup_info,
+ 'path': backup_file
+ }
+
+ except Exception as e:
+ if os.path.exists(backup_file):
+ os.remove(backup_file)
+ return {'success': False, 'error': str(e)}
+
@classmethod
def restore_application(cls, backup_path: str, restore_path: str = None) -> Dict:
"""Restore an application from backup."""
@@ -315,10 +383,13 @@ class BackupService:
search_dirs = [os.path.join(cls.BACKUP_BASE_DIR, 'applications')]
elif backup_type == 'database':
search_dirs = [os.path.join(cls.BACKUP_BASE_DIR, 'databases')]
+ elif backup_type == 'files':
+ search_dirs = [os.path.join(cls.BACKUP_BASE_DIR, 'files')]
else:
search_dirs = [
os.path.join(cls.BACKUP_BASE_DIR, 'applications'),
os.path.join(cls.BACKUP_BASE_DIR, 'databases'),
+ os.path.join(cls.BACKUP_BASE_DIR, 'files'),
os.path.join(cls.BACKUP_BASE_DIR, 'scheduled')
]
@@ -348,8 +419,31 @@ class BackupService:
'path': item_path,
'type': cls.TYPE_DATABASE,
'size': stat.st_size,
- 'timestamp': datetime.fromtimestamp(stat.st_mtime).isoformat()
+ 'timestamp': datetime.fromtimestamp(stat.st_mtime).isoformat(),
+ 'remote_status': 'local'
})
+ elif item.endswith('.tar.gz') and search_dir.endswith('files'):
+ # File backup - check for metadata
+ meta_name = item.replace('.tar.gz', '.json')
+ meta_path = os.path.join(search_dir, meta_name)
+ if os.path.exists(meta_path):
+ try:
+ with open(meta_path, 'r') as f:
+ backup_info = json.load(f)
+ backup_info['path'] = item_path
+ backups.append(backup_info)
+ except Exception:
+ pass
+ else:
+ stat = os.stat(item_path)
+ backups.append({
+ 'name': item,
+ 'path': item_path,
+ 'type': cls.TYPE_FILES,
+ 'size': stat.st_size,
+ 'timestamp': datetime.fromtimestamp(stat.st_mtime).isoformat(),
+ 'remote_status': 'local'
+ })
# Sort by timestamp (newest first)
backups.sort(key=lambda x: x.get('timestamp', ''), reverse=True)
@@ -367,6 +461,11 @@ class BackupService:
shutil.rmtree(backup_path)
elif os.path.exists(backup_path):
os.remove(backup_path)
+ # Also remove metadata file for file backups
+ if backup_path.endswith('.tar.gz'):
+ meta_path = backup_path.replace('.tar.gz', '.json')
+ if os.path.exists(meta_path):
+ os.remove(meta_path)
else:
return {'success': False, 'error': 'Backup not found'}
@@ -407,7 +506,8 @@ class BackupService:
@classmethod
def add_schedule(cls, name: str, backup_type: str, target: str,
- schedule_time: str, days: List[str] = None) -> Dict:
+ schedule_time: str, days: List[str] = None,
+ upload_remote: bool = False) -> Dict:
"""Add a backup schedule."""
config = cls.get_config()
@@ -419,7 +519,9 @@ class BackupService:
'schedule_time': schedule_time,
'days': days or ['daily'],
'enabled': True,
- 'last_run': None
+ 'upload_remote': upload_remote,
+ 'last_run': None,
+ 'last_status': None
}
config.setdefault('schedules', []).append(schedule_entry)
@@ -429,6 +531,24 @@ class BackupService:
return {'success': True, 'schedule': schedule_entry}
return result
+ @classmethod
+ def update_schedule(cls, schedule_id: str, updates: Dict) -> Dict:
+ """Update a backup schedule."""
+ config = cls.get_config()
+ schedules = config.get('schedules', [])
+
+ for i, s in enumerate(schedules):
+ if s.get('id') == schedule_id:
+ allowed_fields = ['name', 'backup_type', 'target', 'schedule_time',
+ 'days', 'enabled', 'upload_remote']
+ for field in allowed_fields:
+ if field in updates:
+ schedules[i][field] = updates[field]
+ config['schedules'] = schedules
+ return cls.save_config(config)
+
+ return {'success': False, 'error': 'Schedule not found'}
+
@classmethod
def remove_schedule(cls, schedule_id: str) -> Dict:
"""Remove a backup schedule."""
@@ -457,15 +577,225 @@ class BackupService:
total_size = sum(b.get('size', 0) for b in backups)
app_backups = [b for b in backups if b.get('type') == cls.TYPE_APP]
db_backups = [b for b in backups if b.get('type') == cls.TYPE_DATABASE]
+ file_backups = [b for b in backups if b.get('type') == cls.TYPE_FILES]
+
+ # Get remote stats
+ remote_stats = {'remote_count': 0, 'remote_size': 0, 'remote_size_human': '0 B'}
+ try:
+ from app.services.storage_provider_service import StorageProviderService
+ storage_config = StorageProviderService.get_config()
+ if storage_config.get('provider', 'local') != 'local':
+ remote_stats = StorageProviderService.get_remote_stats()
+ except Exception:
+ pass
return {
'total_backups': len(backups),
'application_backups': len(app_backups),
'database_backups': len(db_backups),
+ 'file_backups': len(file_backups),
'total_size': total_size,
- 'total_size_human': cls._format_size(total_size)
+ 'total_size_human': cls._format_size(total_size),
+ 'remote_count': remote_stats.get('remote_count', 0),
+ 'remote_size': remote_stats.get('remote_size', 0),
+ 'remote_size_human': remote_stats.get('remote_size_human', '0 B')
}
+ @classmethod
+ def _auto_upload(cls, backup_path: str, backup_info: Dict) -> None:
+ """Auto-upload backup to remote storage if configured."""
+ try:
+ from app.services.storage_provider_service import StorageProviderService
+ storage_config = StorageProviderService.get_config()
+
+ if storage_config.get('provider', 'local') == 'local':
+ return
+ if not storage_config.get('auto_upload', False):
+ return
+
+ if os.path.isdir(backup_path):
+ result = StorageProviderService.upload_directory(backup_path)
+ else:
+ result = StorageProviderService.upload_file(backup_path)
+
+ if result.get('success'):
+ backup_info['remote_status'] = 'synced'
+ backup_info['remote_key'] = result.get('remote_key', '')
+ # Update metadata if it's a directory backup
+ meta_path = os.path.join(backup_path, 'backup.json') if os.path.isdir(backup_path) else None
+ if meta_path and os.path.exists(meta_path):
+ with open(meta_path, 'w') as f:
+ json.dump(backup_info, f, indent=2)
+ except Exception:
+ pass
+
+ # --- Scheduler ---
+
+ @classmethod
+ def start_scheduler(cls) -> None:
+ """Start the backup scheduler background thread."""
+ if cls._scheduler_thread and cls._scheduler_thread.is_alive():
+ return
+
+ cls._stop_scheduler = False
+ cls._scheduler_thread = threading.Thread(
+ target=cls._scheduler_loop,
+ daemon=True,
+ name='backup-scheduler'
+ )
+ cls._scheduler_thread.start()
+
+ @classmethod
+ def stop_scheduler(cls) -> None:
+ """Stop the backup scheduler."""
+ cls._stop_scheduler = True
+ if cls._scheduler_thread:
+ cls._scheduler_thread.join(timeout=5)
+ cls._scheduler_thread = None
+
+ @classmethod
+ def _scheduler_loop(cls) -> None:
+ """Background loop that checks and runs scheduled backups."""
+ while not cls._stop_scheduler:
+ try:
+ config = cls.get_config()
+ if config.get('enabled', False):
+ now = datetime.now()
+ current_time = now.strftime('%H:%M')
+ current_day = now.strftime('%A').lower()
+
+ for sched in config.get('schedules', []):
+ if not sched.get('enabled', False):
+ continue
+
+ # Check if it's time to run
+ if sched.get('schedule_time') != current_time:
+ continue
+
+ # Check day
+ days = sched.get('days', ['daily'])
+ if 'daily' not in days and current_day not in days:
+ continue
+
+ # Check if already ran this minute
+ last_run = sched.get('last_run')
+ if last_run:
+ try:
+ last_run_time = datetime.fromisoformat(last_run)
+ if (now - last_run_time).total_seconds() < 120:
+ continue
+ except Exception:
+ pass
+
+ # Run the backup
+ cls._run_scheduled_backup(sched)
+
+ # Run retention cleanup once daily at midnight
+ if current_time == '00:00':
+ cls.cleanup_old_backups()
+
+ except Exception:
+ pass
+
+ # Check every 30 seconds
+ for _ in range(30):
+ if cls._stop_scheduler:
+ return
+ time.sleep(1)
+
+ @classmethod
+ def _run_scheduled_backup(cls, sched: Dict) -> None:
+ """Execute a single scheduled backup."""
+ backup_type = sched.get('backup_type', 'database')
+ target = sched.get('target', '')
+ result = None
+
+ try:
+ if backup_type == 'database':
+ # Parse target as db_type:db_name or just db_name
+ parts = target.split(':')
+ if len(parts) == 2:
+ db_type, db_name = parts
+ else:
+ db_type, db_name = 'mysql', target
+ result = cls.backup_database(db_type, db_name)
+
+ elif backup_type == 'application':
+ from app.models import Application
+ app = Application.query.filter_by(name=target).first()
+ if app:
+ result = cls.backup_application(app.name, app.root_path)
+ else:
+ result = {'success': False, 'error': f'Application "{target}" not found'}
+
+ elif backup_type == 'files':
+ paths_list = [p.strip() for p in target.split(',') if p.strip()]
+ result = cls.backup_files(paths_list, backup_name=f"scheduled_{sched.get('name', 'backup')}")
+
+ # Upload to remote if configured on this schedule
+ if result and result.get('success') and sched.get('upload_remote', False):
+ try:
+ from app.services.storage_provider_service import StorageProviderService
+ backup_path = result.get('path') or result.get('backup', {}).get('path')
+ if backup_path:
+ if os.path.isdir(backup_path):
+ StorageProviderService.upload_directory(backup_path)
+ else:
+ StorageProviderService.upload_file(backup_path)
+ except Exception:
+ pass
+
+ # Update schedule status
+ config = cls.get_config()
+ for s in config.get('schedules', []):
+ if s.get('id') == sched.get('id'):
+ s['last_run'] = datetime.now().isoformat()
+ s['last_status'] = 'success' if result and result.get('success') else 'failed'
+ break
+ cls.save_config(config)
+
+ # Send notification on failure
+ if result and not result.get('success'):
+ cls._send_backup_notification(
+ sched.get('name', 'Backup'),
+ False,
+ result.get('error', 'Unknown error')
+ )
+
+ except Exception as e:
+ # Update schedule status on exception
+ config = cls.get_config()
+ for s in config.get('schedules', []):
+ if s.get('id') == sched.get('id'):
+ s['last_run'] = datetime.now().isoformat()
+ s['last_status'] = 'failed'
+ break
+ cls.save_config(config)
+ cls._send_backup_notification(sched.get('name', 'Backup'), False, str(e))
+
+ @classmethod
+ def _send_backup_notification(cls, backup_name: str, success: bool, message: str) -> None:
+ """Send a notification about backup status."""
+ try:
+ from app.services.notification_service import NotificationService
+ config = cls.get_config()
+ notifications = config.get('notifications', {})
+
+ if success and not notifications.get('on_success', False):
+ return
+ if not success and not notifications.get('on_failure', True):
+ return
+
+ severity = 'success' if success else 'critical'
+ status = 'completed successfully' if success else 'failed'
+ NotificationService.send_all(
+ title=f'Backup {status}: {backup_name}',
+ message=message,
+ severity=severity
+ )
+ except Exception:
+ pass
+
@staticmethod
def _format_size(size: int) -> str:
"""Format size in human readable format."""
diff --git a/backend/app/services/storage_provider_service.py b/backend/app/services/storage_provider_service.py
new file mode 100644
index 00000000..5da38a0f
--- /dev/null
+++ b/backend/app/services/storage_provider_service.py
@@ -0,0 +1,368 @@
+import os
+import json
+import hashlib
+from datetime import datetime
+from typing import Dict, List, Optional
+
+from app import paths
+
+
+class StorageProviderService:
+ """Service for managing remote backup storage (S3-compatible, Backblaze B2)."""
+
+ CONFIG_FILE = os.path.join(paths.SERVERKIT_CONFIG_DIR, 'storage.json')
+
+ @classmethod
+ def get_config(cls) -> Dict:
+ """Get storage provider configuration."""
+ if os.path.exists(cls.CONFIG_FILE):
+ try:
+ with open(cls.CONFIG_FILE, 'r') as f:
+ return json.load(f)
+ except Exception:
+ pass
+
+ return {
+ 'provider': 'local',
+ 's3': {
+ 'bucket': '',
+ 'region': 'us-east-1',
+ 'access_key': '',
+ 'secret_key': '',
+ 'endpoint_url': '',
+ 'path_prefix': 'serverkit-backups'
+ },
+ 'b2': {
+ 'bucket': '',
+ 'key_id': '',
+ 'application_key': '',
+ 'endpoint_url': '',
+ 'path_prefix': 'serverkit-backups'
+ },
+ 'auto_upload': False,
+ 'keep_local_copy': True
+ }
+
+ @classmethod
+ def get_config_masked(cls) -> Dict:
+ """Get storage config with secrets masked."""
+ config = cls.get_config()
+ masked = json.loads(json.dumps(config))
+
+ secret_fields = {
+ 's3': ['access_key', 'secret_key'],
+ 'b2': ['key_id', 'application_key']
+ }
+
+ for provider, fields in secret_fields.items():
+ if provider in masked:
+ for field in fields:
+ val = masked[provider].get(field, '')
+ if val and len(val) > 4:
+ masked[provider][field] = val[:4] + '*' * (len(val) - 4)
+
+ return masked
+
+ @classmethod
+ def save_config(cls, config: Dict) -> Dict:
+ """Save storage provider configuration."""
+ try:
+ os.makedirs(paths.SERVERKIT_CONFIG_DIR, exist_ok=True)
+
+ # Merge with existing config to preserve unmasked secrets
+ existing = cls.get_config()
+ secret_fields = {
+ 's3': ['access_key', 'secret_key'],
+ 'b2': ['key_id', 'application_key']
+ }
+
+ for provider, fields in secret_fields.items():
+ if provider in config:
+ for field in fields:
+ new_val = config[provider].get(field, '')
+ if new_val and '*' in new_val:
+ # Keep existing value if masked
+ config[provider][field] = existing.get(provider, {}).get(field, '')
+
+ with open(cls.CONFIG_FILE, 'w') as f:
+ json.dump(config, f, indent=2)
+ return {'success': True, 'message': 'Storage configuration saved'}
+ except Exception as e:
+ return {'success': False, 'error': str(e)}
+
+ @classmethod
+ def _get_client(cls, config: Dict = None):
+ """Get boto3 S3 client based on config."""
+ import boto3
+
+ if config is None:
+ config = cls.get_config()
+
+ provider = config.get('provider', 'local')
+ if provider == 'local':
+ return None, None, None
+
+ if provider == 's3':
+ provider_config = config.get('s3', {})
+ client = boto3.client(
+ 's3',
+ region_name=provider_config.get('region', 'us-east-1'),
+ aws_access_key_id=provider_config.get('access_key'),
+ aws_secret_access_key=provider_config.get('secret_key'),
+ endpoint_url=provider_config.get('endpoint_url') or None
+ )
+ bucket = provider_config.get('bucket', '')
+ prefix = provider_config.get('path_prefix', 'serverkit-backups')
+
+ elif provider == 'b2':
+ provider_config = config.get('b2', {})
+ client = boto3.client(
+ 's3',
+ endpoint_url=provider_config.get('endpoint_url'),
+ aws_access_key_id=provider_config.get('key_id'),
+ aws_secret_access_key=provider_config.get('application_key')
+ )
+ bucket = provider_config.get('bucket', '')
+ prefix = provider_config.get('path_prefix', 'serverkit-backups')
+
+ else:
+ return None, None, None
+
+ return client, bucket, prefix
+
+ @classmethod
+ def test_connection(cls, config: Dict = None) -> Dict:
+ """Test connection to storage provider."""
+ try:
+ client, bucket, prefix = cls._get_client(config)
+ if client is None:
+ return {'success': False, 'error': 'No remote provider configured'}
+
+ # Try to list objects (limited to 1) to verify access
+ client.list_objects_v2(Bucket=bucket, Prefix=prefix, MaxKeys=1)
+
+ return {
+ 'success': True,
+ 'message': f'Connected to bucket "{bucket}" successfully'
+ }
+ except Exception as e:
+ error_msg = str(e)
+ if 'NoSuchBucket' in error_msg:
+ return {'success': False, 'error': f'Bucket "{bucket}" does not exist'}
+ if 'AccessDenied' in error_msg or 'InvalidAccessKeyId' in error_msg:
+ return {'success': False, 'error': 'Access denied - check your credentials'}
+ return {'success': False, 'error': error_msg}
+
+ @classmethod
+ def upload_file(cls, local_path: str, remote_key: str = None) -> Dict:
+ """Upload a file to remote storage."""
+ try:
+ client, bucket, prefix = cls._get_client()
+ if client is None:
+ return {'success': False, 'error': 'No remote provider configured'}
+
+ if not os.path.exists(local_path):
+ return {'success': False, 'error': f'Local file not found: {local_path}'}
+
+ if remote_key is None:
+ # Use relative path from backup dir as key
+ remote_key = os.path.relpath(local_path, paths.SERVERKIT_BACKUP_DIR)
+
+ full_key = f"{prefix}/{remote_key}" if prefix else remote_key
+
+ file_size = os.path.getsize(local_path)
+
+ # Use multipart upload for files > 100MB
+ from boto3.s3.transfer import TransferConfig
+ transfer_config = TransferConfig(
+ multipart_threshold=100 * 1024 * 1024,
+ multipart_chunksize=50 * 1024 * 1024
+ )
+
+ client.upload_file(
+ local_path, bucket, full_key,
+ Config=transfer_config
+ )
+
+ return {
+ 'success': True,
+ 'message': f'Uploaded to {full_key}',
+ 'remote_key': full_key,
+ 'size': file_size
+ }
+ except Exception as e:
+ return {'success': False, 'error': str(e)}
+
+ @classmethod
+ def upload_directory(cls, local_dir: str, remote_prefix: str = None) -> Dict:
+ """Upload all files in a directory to remote storage."""
+ try:
+ client, bucket, prefix = cls._get_client()
+ if client is None:
+ return {'success': False, 'error': 'No remote provider configured'}
+
+ if not os.path.isdir(local_dir):
+ return {'success': False, 'error': f'Directory not found: {local_dir}'}
+
+ if remote_prefix is None:
+ remote_prefix = os.path.relpath(local_dir, paths.SERVERKIT_BACKUP_DIR)
+
+ uploaded = 0
+ total_size = 0
+
+ for root, dirs, files in os.walk(local_dir):
+ for filename in files:
+ local_path = os.path.join(root, filename)
+ rel_path = os.path.relpath(local_path, local_dir)
+ full_key = f"{prefix}/{remote_prefix}/{rel_path}" if prefix else f"{remote_prefix}/{rel_path}"
+
+ client.upload_file(local_path, bucket, full_key)
+ uploaded += 1
+ total_size += os.path.getsize(local_path)
+
+ return {
+ 'success': True,
+ 'message': f'Uploaded {uploaded} file(s)',
+ 'files_uploaded': uploaded,
+ 'total_size': total_size
+ }
+ except Exception as e:
+ return {'success': False, 'error': str(e)}
+
+ @classmethod
+ def download_file(cls, remote_key: str, local_path: str) -> Dict:
+ """Download a file from remote storage."""
+ try:
+ client, bucket, prefix = cls._get_client()
+ if client is None:
+ return {'success': False, 'error': 'No remote provider configured'}
+
+ os.makedirs(os.path.dirname(local_path), exist_ok=True)
+
+ client.download_file(bucket, remote_key, local_path)
+
+ return {
+ 'success': True,
+ 'message': f'Downloaded to {local_path}',
+ 'local_path': local_path,
+ 'size': os.path.getsize(local_path)
+ }
+ except Exception as e:
+ return {'success': False, 'error': str(e)}
+
+ @classmethod
+ def delete_file(cls, remote_key: str) -> Dict:
+ """Delete a file from remote storage."""
+ try:
+ client, bucket, prefix = cls._get_client()
+ if client is None:
+ return {'success': False, 'error': 'No remote provider configured'}
+
+ client.delete_object(Bucket=bucket, Key=remote_key)
+
+ return {'success': True, 'message': f'Deleted {remote_key}'}
+ except Exception as e:
+ return {'success': False, 'error': str(e)}
+
+ @classmethod
+ def list_files(cls, prefix_filter: str = None) -> Dict:
+ """List files in remote storage."""
+ try:
+ client, bucket, prefix = cls._get_client()
+ if client is None:
+ return {'success': False, 'error': 'No remote provider configured'}
+
+ search_prefix = prefix or ''
+ if prefix_filter:
+ search_prefix = f"{search_prefix}/{prefix_filter}" if search_prefix else prefix_filter
+
+ files = []
+ paginator = client.get_paginator('list_objects_v2')
+
+ for page in paginator.paginate(Bucket=bucket, Prefix=search_prefix):
+ for obj in page.get('Contents', []):
+ files.append({
+ 'key': obj['Key'],
+ 'size': obj['Size'],
+ 'last_modified': obj['LastModified'].isoformat(),
+ 'etag': obj.get('ETag', '').strip('"')
+ })
+
+ return {
+ 'success': True,
+ 'files': files,
+ 'total_count': len(files),
+ 'total_size': sum(f['size'] for f in files)
+ }
+ except Exception as e:
+ return {'success': False, 'error': str(e)}
+
+ @classmethod
+ def verify_file(cls, remote_key: str, local_path: str) -> Dict:
+ """Verify a remote file matches the local file (size + MD5)."""
+ try:
+ client, bucket, prefix = cls._get_client()
+ if client is None:
+ return {'success': False, 'error': 'No remote provider configured'}
+
+ if not os.path.exists(local_path):
+ return {'success': False, 'error': 'Local file not found', 'verified': False}
+
+ # Get remote file metadata
+ response = client.head_object(Bucket=bucket, Key=remote_key)
+ remote_size = response['ContentLength']
+ remote_etag = response.get('ETag', '').strip('"')
+
+ # Compare size
+ local_size = os.path.getsize(local_path)
+ size_match = remote_size == local_size
+
+ # Compute local MD5 for simple files (non-multipart)
+ md5_match = None
+ if '-' not in remote_etag:
+ md5 = hashlib.md5()
+ with open(local_path, 'rb') as f:
+ for chunk in iter(lambda: f.read(8192), b''):
+ md5.update(chunk)
+ local_md5 = md5.hexdigest()
+ md5_match = local_md5 == remote_etag
+
+ verified = size_match and (md5_match is None or md5_match)
+
+ return {
+ 'success': True,
+ 'verified': verified,
+ 'local_size': local_size,
+ 'remote_size': remote_size,
+ 'size_match': size_match,
+ 'md5_match': md5_match
+ }
+ except Exception as e:
+ return {'success': False, 'error': str(e), 'verified': False}
+
+ @classmethod
+ def get_remote_stats(cls) -> Dict:
+ """Get statistics about remote storage usage."""
+ result = cls.list_files()
+ if not result.get('success'):
+ return {
+ 'remote_count': 0,
+ 'remote_size': 0,
+ 'remote_size_human': '0 B'
+ }
+
+ total_size = result.get('total_size', 0)
+ return {
+ 'remote_count': result.get('total_count', 0),
+ 'remote_size': total_size,
+ 'remote_size_human': cls._format_size(total_size)
+ }
+
+ @staticmethod
+ def _format_size(size: int) -> str:
+ """Format size in human readable format."""
+ for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
+ if size < 1024:
+ return f"{size:.1f} {unit}"
+ size /= 1024
+ return f"{size:.1f} PB"
diff --git a/backend/requirements.txt b/backend/requirements.txt
index 9dd9c180..6eba1fa5 100644
--- a/backend/requirements.txt
+++ b/backend/requirements.txt
@@ -50,4 +50,7 @@ pyotp==2.9.0
qrcode[pil]==7.4.2
# HTTP Requests (for webhooks & notifications)
-requests==2.32.5
\ No newline at end of file
+requests==2.32.5
+
+# S3-compatible storage (AWS S3, Backblaze B2, MinIO, Wasabi)
+boto3==1.35.0
\ No newline at end of file
diff --git a/frontend/src/pages/Backups.jsx b/frontend/src/pages/Backups.jsx
index b8457433..0dbd3322 100644
--- a/frontend/src/pages/Backups.jsx
+++ b/frontend/src/pages/Backups.jsx
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from 'react';
+import { Upload, Download, Check, AlertTriangle, Clock, Database, Package, FolderArchive, HardDrive, Cloud, CloudOff, RefreshCw, Trash2, Plus, Settings, CheckCircle, XCircle, Server, FileArchive } from 'lucide-react';
import api from '../services/api';
import { useToast } from '../contexts/ToastContext';
@@ -8,6 +9,7 @@ const Backups = () => {
const [stats, setStats] = useState(null);
const [schedules, setSchedules] = useState([]);
const [config, setConfig] = useState(null);
+ const [storageConfig, setStorageConfig] = useState(null);
const [apps, setApps] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
@@ -19,6 +21,8 @@ const Backups = () => {
const [showScheduleModal, setShowScheduleModal] = useState(false);
const [showRestoreModal, setShowRestoreModal] = useState(false);
const [selectedBackup, setSelectedBackup] = useState(null);
+ const [uploadingBackup, setUploadingBackup] = useState(null);
+ const [testingConnection, setTestingConnection] = useState(false);
// Backup form state
const [backupForm, setBackupForm] = useState({
@@ -29,7 +33,9 @@ const Backups = () => {
dbName: '',
dbUser: '',
dbPassword: '',
- dbHost: 'localhost'
+ dbHost: 'localhost',
+ filePaths: '',
+ fileName: ''
});
// Schedule form state
@@ -38,7 +44,8 @@ const Backups = () => {
backupType: 'application',
target: '',
scheduleTime: '02:00',
- days: ['daily']
+ days: ['daily'],
+ uploadRemote: false
});
// Config form state
@@ -47,6 +54,15 @@ const Backups = () => {
retention_days: 30
});
+ // Storage config form state
+ const [storageForm, setStorageForm] = useState({
+ provider: 'local',
+ s3: { bucket: '', region: 'us-east-1', access_key: '', secret_key: '', endpoint_url: '', path_prefix: 'serverkit-backups' },
+ b2: { bucket: '', key_id: '', application_key: '', endpoint_url: '', path_prefix: 'serverkit-backups' },
+ auto_upload: false,
+ keep_local_copy: true
+ });
+
useEffect(() => {
loadData();
}, []);
@@ -54,12 +70,13 @@ const Backups = () => {
const loadData = async () => {
try {
setLoading(true);
- const [backupsRes, statsRes, schedulesRes, configRes, appsRes] = await Promise.all([
+ const [backupsRes, statsRes, schedulesRes, configRes, appsRes, storageRes] = await Promise.all([
api.getBackups(),
api.getBackupStats(),
api.getBackupSchedules(),
api.getBackupConfig(),
- api.getApps()
+ api.getApps(),
+ api.getStorageConfig().catch(() => null)
]);
setBackups(backupsRes.backups || []);
@@ -68,6 +85,11 @@ const Backups = () => {
setConfig(configRes);
setApps(appsRes.applications || []);
+ if (storageRes) {
+ setStorageConfig(storageRes);
+ setStorageForm(storageRes);
+ }
+
if (configRes) {
setConfigForm({
enabled: configRes.enabled || false,
@@ -93,7 +115,8 @@ const Backups = () => {
host: backupForm.dbHost
} : null;
await api.backupApplication(parseInt(backupForm.applicationId), backupForm.includeDb, dbConfig);
- } else {
+ toast.success('Application backup created');
+ } else if (backupForm.type === 'database') {
await api.backupDatabase(
backupForm.dbType,
backupForm.dbName,
@@ -101,12 +124,21 @@ const Backups = () => {
backupForm.dbPassword,
backupForm.dbHost
);
+ toast.success('Database backup created');
+ } else if (backupForm.type === 'files') {
+ const paths = backupForm.filePaths.split('\n').map(p => p.trim()).filter(Boolean);
+ if (paths.length === 0) {
+ toast.error('Enter at least one file path');
+ return;
+ }
+ await api.backupFiles(paths, backupForm.fileName || null);
+ toast.success('File backup created');
}
setShowBackupModal(false);
resetBackupForm();
loadData();
} catch (err) {
- setError(err.message);
+ toast.error(err.message);
}
};
@@ -114,9 +146,23 @@ const Backups = () => {
if (!window.confirm('Are you sure you want to delete this backup?')) return;
try {
await api.deleteBackup(backupPath);
+ toast.success('Backup deleted');
loadData();
} catch (err) {
- setError(err.message);
+ toast.error(err.message);
+ }
+ };
+
+ const handleUploadToRemote = async (backup) => {
+ setUploadingBackup(backup.path);
+ try {
+ await api.uploadBackupToRemote(backup.path);
+ toast.success('Backup uploaded to remote storage');
+ loadData();
+ } catch (err) {
+ toast.error(err.message);
+ } finally {
+ setUploadingBackup(null);
}
};
@@ -150,13 +196,25 @@ const Backups = () => {
scheduleForm.backupType,
scheduleForm.target,
scheduleForm.scheduleTime,
- scheduleForm.days
+ scheduleForm.days,
+ scheduleForm.uploadRemote
);
+ toast.success('Schedule added');
setShowScheduleModal(false);
resetScheduleForm();
loadData();
} catch (err) {
- setError(err.message);
+ toast.error(err.message);
+ }
+ };
+
+ const handleToggleSchedule = async (schedule) => {
+ try {
+ await api.updateBackupSchedule(schedule.id, { enabled: !schedule.enabled });
+ toast.success(`Schedule ${schedule.enabled ? 'disabled' : 'enabled'}`);
+ loadData();
+ } catch (err) {
+ toast.error(err.message);
}
};
@@ -164,9 +222,10 @@ const Backups = () => {
if (!window.confirm('Are you sure you want to remove this schedule?')) return;
try {
await api.removeBackupSchedule(scheduleId);
+ toast.success('Schedule removed');
loadData();
} catch (err) {
- setError(err.message);
+ toast.error(err.message);
}
};
@@ -174,9 +233,37 @@ const Backups = () => {
e.preventDefault();
try {
await api.updateBackupConfig(configForm);
+ toast.success('Settings saved');
loadData();
} catch (err) {
- setError(err.message);
+ toast.error(err.message);
+ }
+ };
+
+ const handleSaveStorageConfig = async (e) => {
+ e.preventDefault();
+ try {
+ await api.updateStorageConfig(storageForm);
+ toast.success('Storage configuration saved');
+ loadData();
+ } catch (err) {
+ toast.error(err.message);
+ }
+ };
+
+ const handleTestConnection = async () => {
+ setTestingConnection(true);
+ try {
+ const result = await api.testStorageConnection(storageForm);
+ if (result.success) {
+ toast.success(result.message);
+ } else {
+ toast.error(result.error);
+ }
+ } catch (err) {
+ toast.error(err.message);
+ } finally {
+ setTestingConnection(false);
}
};
@@ -200,7 +287,9 @@ const Backups = () => {
dbName: '',
dbUser: '',
dbPassword: '',
- dbHost: 'localhost'
+ dbHost: 'localhost',
+ filePaths: '',
+ fileName: ''
});
};
@@ -210,7 +299,8 @@ const Backups = () => {
backupType: 'application',
target: '',
scheduleTime: '02:00',
- days: ['daily']
+ days: ['daily'],
+ uploadRemote: false
});
};
@@ -230,6 +320,26 @@ const Backups = () => {
return new Date(timestamp).toLocaleString();
};
+ const getBackupIcon = (type) => {
+ switch (type) {
+ case 'application': return <Package size={16} />;
+ case 'database': return <Database size={16} />;
+ case 'files': return <FolderArchive size={16} />;
+ default: return <FileArchive size={16} />;
+ }
+ };
+
+ const getRemoteStatusBadge = (status) => {
+ switch (status) {
+ case 'synced':
+ return <span className="badge badge-success"><Cloud size={12} /> Synced</span>;
+ case 'remote-only':
+ return <span className="badge badge-info"><Cloud size={12} /> Remote</span>;
+ default:
+ return <span className="badge badge-secondary"><HardDrive size={12} /> Local</span>;
+ }
+ };
+
const filteredBackups = filterType === 'all'
? backups
: backups.filter(b => b.type === filterType);
@@ -243,21 +353,15 @@ const Backups = () => {
<div className="page-header">
<div>
<h1>Backups</h1>
- <p className="page-subtitle">Manage application and database backups</p>
+ <p className="page-subtitle">Manage application, database, and file backups with local and remote storage</p>
</div>
<div className="page-actions">
<button className="btn btn-secondary" onClick={() => setShowScheduleModal(true)}>
- <svg viewBox="0 0 24 24" width="16" height="16">
- <circle cx="12" cy="12" r="10"/>
- <polyline points="12 6 12 12 16 14"/>
- </svg>
+ <Clock size={16} />
Add Schedule
</button>
<button className="btn btn-primary" onClick={() => setShowBackupModal(true)}>
- <svg viewBox="0 0 24 24" width="16" height="16">
- <line x1="12" y1="5" x2="12" y2="19"/>
- <line x1="5" y1="12" x2="19" y2="12"/>
- </svg>
+ <Plus size={16} />
Create Backup
</button>
</div>
@@ -274,11 +378,7 @@ const Backups = () => {
<div className="stats-grid">
<div className="stat-card">
<div className="stat-icon backups">
- <svg viewBox="0 0 24 24" width="24" height="24">
- <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
- <polyline points="7 10 12 15 17 10"/>
- <line x1="12" y1="15" x2="12" y2="3"/>
- </svg>
+ <Download size={24} />
</div>
<div className="stat-content">
<span className="stat-label">Total Backups</span>
@@ -288,9 +388,7 @@ const Backups = () => {
<div className="stat-card">
<div className="stat-icon apps">
- <svg viewBox="0 0 24 24" width="24" height="24">
- <path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/>
- </svg>
+ <Package size={24} />
</div>
<div className="stat-content">
<span className="stat-label">Application Backups</span>
@@ -300,11 +398,7 @@ const Backups = () => {
<div className="stat-card">
<div className="stat-icon databases">
- <svg viewBox="0 0 24 24" width="24" height="24">
- <ellipse cx="12" cy="5" rx="9" ry="3"/>
- <path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/>
- <path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/>
- </svg>
+ <Database size={24} />
</div>
<div className="stat-content">
<span className="stat-label">Database Backups</span>
@@ -314,41 +408,43 @@ const Backups = () => {
<div className="stat-card">
<div className="stat-icon size">
- <svg viewBox="0 0 24 24" width="24" height="24">
- <rect x="2" y="2" width="20" height="8" rx="2" ry="2"/>
- <rect x="2" y="14" width="20" height="8" rx="2" ry="2"/>
- <line x1="6" y1="6" x2="6.01" y2="6"/>
- <line x1="6" y1="18" x2="6.01" y2="18"/>
- </svg>
+ <HardDrive size={24} />
</div>
<div className="stat-content">
- <span className="stat-label">Total Size</span>
+ <span className="stat-label">Local Size</span>
<span className="stat-value">{stats?.total_size_human || '0 B'}</span>
</div>
</div>
+
+ {storageConfig?.provider !== 'local' && (
+ <div className="stat-card">
+ <div className="stat-icon cloud">
+ <Cloud size={24} />
+ </div>
+ <div className="stat-content">
+ <span className="stat-label">Remote Backups</span>
+ <span className="stat-value">{stats?.remote_count || 0}</span>
+ </div>
+ </div>
+ )}
</div>
<div className="tabs">
- <button
- className={`tab ${activeTab === 'backups' ? 'active' : ''}`}
- onClick={() => setActiveTab('backups')}
- >
+ <button className={`tab ${activeTab === 'backups' ? 'active' : ''}`} onClick={() => setActiveTab('backups')}>
Backups
</button>
- <button
- className={`tab ${activeTab === 'schedules' ? 'active' : ''}`}
- onClick={() => setActiveTab('schedules')}
- >
+ <button className={`tab ${activeTab === 'schedules' ? 'active' : ''}`} onClick={() => setActiveTab('schedules')}>
Schedules
</button>
- <button
- className={`tab ${activeTab === 'settings' ? 'active' : ''}`}
- onClick={() => setActiveTab('settings')}
- >
+ <button className={`tab ${activeTab === 'storage' ? 'active' : ''}`} onClick={() => setActiveTab('storage')}>
+ Storage
+ </button>
+ <button className={`tab ${activeTab === 'settings' ? 'active' : ''}`} onClick={() => setActiveTab('settings')}>
Settings
</button>
</div>
+ {/* Backups Tab */}
{activeTab === 'backups' && (
<div className="card">
<div className="card-header">
@@ -362,8 +458,10 @@ const Backups = () => {
<option value="all">All Types</option>
<option value="application">Applications</option>
<option value="database">Databases</option>
+ <option value="files">Files</option>
</select>
<button className="btn btn-secondary btn-sm" onClick={loadData}>
+ <RefreshCw size={14} />
Refresh
</button>
</div>
@@ -371,11 +469,7 @@ const Backups = () => {
<div className="card-body">
{filteredBackups.length === 0 ? (
<div className="empty-state">
- <svg viewBox="0 0 24 24" width="48" height="48">
- <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
- <polyline points="7 10 12 15 17 10"/>
- <line x1="12" y1="15" x2="12" y2="3"/>
- </svg>
+ <Download size={48} />
<h3>No Backups</h3>
<p>No backups found. Create your first backup to get started.</p>
<button className="btn btn-primary" onClick={() => setShowBackupModal(true)}>
@@ -389,6 +483,7 @@ const Backups = () => {
<th>Name</th>
<th>Type</th>
<th>Size</th>
+ <th>Storage</th>
<th>Created</th>
<th>Actions</th>
</tr>
@@ -398,51 +493,52 @@ const Backups = () => {
<tr key={index}>
<td>
<div className="backup-name">
- {backup.type === 'application' ? (
- <svg viewBox="0 0 24 24" width="16" height="16" className="icon-app">
- <path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/>
- </svg>
- ) : (
- <svg viewBox="0 0 24 24" width="16" height="16" className="icon-db">
- <ellipse cx="12" cy="5" rx="9" ry="3"/>
- <path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/>
- <path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/>
- </svg>
- )}
+ {getBackupIcon(backup.type)}
<span>{backup.name || backup.app_name}</span>
</div>
</td>
<td>
- <span className={`badge badge-${backup.type === 'application' ? 'primary' : 'info'}`}>
+ <span className={`badge badge-${backup.type === 'application' ? 'primary' : backup.type === 'database' ? 'info' : 'warning'}`}>
{backup.type}
</span>
</td>
<td>{formatSize(backup.size)}</td>
+ <td>{getRemoteStatusBadge(backup.remote_status)}</td>
<td>{formatTimestamp(backup.timestamp)}</td>
<td>
<div className="action-buttons">
- <button
- className="btn btn-sm btn-secondary"
- onClick={() => {
- setSelectedBackup(backup);
- setShowRestoreModal(true);
- }}
- title="Restore"
- >
- <svg viewBox="0 0 24 24" width="14" height="14">
- <polyline points="1 4 1 10 7 10"/>
- <path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/>
- </svg>
- </button>
+ {backup.type !== 'files' && (
+ <button
+ className="btn btn-sm btn-secondary"
+ onClick={() => {
+ setSelectedBackup(backup);
+ setShowRestoreModal(true);
+ }}
+ title="Restore"
+ >
+ <RefreshCw size={14} />
+ </button>
+ )}
+ {storageConfig?.provider !== 'local' && backup.remote_status !== 'synced' && (
+ <button
+ className="btn btn-sm btn-secondary"
+ onClick={() => handleUploadToRemote(backup)}
+ disabled={uploadingBackup === backup.path}
+ title="Upload to Remote"
+ >
+ {uploadingBackup === backup.path ? (
+ <RefreshCw size={14} className="spinning" />
+ ) : (
+ <Upload size={14} />
+ )}
+ </button>
+ )}
<button
className="btn btn-sm btn-danger"
onClick={() => handleDeleteBackup(backup.path)}
title="Delete"
>
- <svg viewBox="0 0 24 24" width="14" height="14">
- <polyline points="3 6 5 6 21 6"/>
- <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
- </svg>
+ <Trash2 size={14} />
</button>
</div>
</td>
@@ -455,21 +551,20 @@ const Backups = () => {
</div>
)}
+ {/* Schedules Tab */}
{activeTab === 'schedules' && (
<div className="card">
<div className="card-header">
<h3>Backup Schedules</h3>
<button className="btn btn-primary btn-sm" onClick={() => setShowScheduleModal(true)}>
+ <Plus size={14} />
Add Schedule
</button>
</div>
<div className="card-body">
{schedules.length === 0 ? (
<div className="empty-state">
- <svg viewBox="0 0 24 24" width="48" height="48">
- <circle cx="12" cy="12" r="10"/>
- <polyline points="12 6 12 12 16 14"/>
- </svg>
+ <Clock size={48} />
<h3>No Schedules</h3>
<p>No backup schedules configured. Add a schedule for automated backups.</p>
<button className="btn btn-primary" onClick={() => setShowScheduleModal(true)}>
@@ -485,6 +580,8 @@ const Backups = () => {
<th>Target</th>
<th>Time</th>
<th>Days</th>
+ <th>Remote</th>
+ <th>Last Run</th>
<th>Status</th>
<th>Actions</th>
</tr>
@@ -494,7 +591,7 @@ const Backups = () => {
<tr key={schedule.id}>
<td>{schedule.name}</td>
<td>
- <span className={`badge badge-${schedule.backup_type === 'application' ? 'primary' : 'info'}`}>
+ <span className={`badge badge-${schedule.backup_type === 'application' ? 'primary' : schedule.backup_type === 'database' ? 'info' : 'warning'}`}>
{schedule.backup_type}
</span>
</td>
@@ -502,21 +599,43 @@ const Backups = () => {
<td>{schedule.schedule_time}</td>
<td>{schedule.days?.join(', ') || 'daily'}</td>
<td>
- <span className={`badge badge-${schedule.enabled ? 'success' : 'secondary'}`}>
- {schedule.enabled ? 'Active' : 'Disabled'}
- </span>
+ {schedule.upload_remote ? (
+ <Cloud size={16} className="text-success" />
+ ) : (
+ <CloudOff size={16} className="text-muted" />
+ )}
</td>
+ <td>{schedule.last_run ? formatTimestamp(schedule.last_run) : 'Never'}</td>
<td>
- <button
- className="btn btn-sm btn-danger"
- onClick={() => handleRemoveSchedule(schedule.id)}
- title="Remove"
- >
- <svg viewBox="0 0 24 24" width="14" height="14">
- <polyline points="3 6 5 6 21 6"/>
- <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
- </svg>
- </button>
+ {schedule.last_status === 'success' && (
+ <span className="badge badge-success"><CheckCircle size={12} /> Success</span>
+ )}
+ {schedule.last_status === 'failed' && (
+ <span className="badge badge-danger"><XCircle size={12} /> Failed</span>
+ )}
+ {!schedule.last_status && (
+ <span className={`badge badge-${schedule.enabled ? 'success' : 'secondary'}`}>
+ {schedule.enabled ? 'Active' : 'Disabled'}
+ </span>
+ )}
+ </td>
+ <td>
+ <div className="action-buttons">
+ <button
+ className={`btn btn-sm ${schedule.enabled ? 'btn-secondary' : 'btn-success'}`}
+ onClick={() => handleToggleSchedule(schedule)}
+ title={schedule.enabled ? 'Disable' : 'Enable'}
+ >
+ {schedule.enabled ? <XCircle size={14} /> : <CheckCircle size={14} />}
+ </button>
+ <button
+ className="btn btn-sm btn-danger"
+ onClick={() => handleRemoveSchedule(schedule.id)}
+ title="Remove"
+ >
+ <Trash2 size={14} />
+ </button>
+ </div>
</td>
</tr>
))}
@@ -527,6 +646,200 @@ const Backups = () => {
</div>
)}
+ {/* Storage Tab */}
+ {activeTab === 'storage' && (
+ <div className="card">
+ <div className="card-header">
+ <h3>Remote Storage Configuration</h3>
+ </div>
+ <div className="card-body">
+ <form onSubmit={handleSaveStorageConfig}>
+ <div className="form-group">
+ <label>Storage Provider</label>
+ <select
+ value={storageForm.provider}
+ onChange={(e) => setStorageForm({...storageForm, provider: e.target.value})}
+ >
+ <option value="local">Local Only</option>
+ <option value="s3">S3-Compatible (AWS S3, MinIO, Wasabi)</option>
+ <option value="b2">Backblaze B2</option>
+ </select>
+ </div>
+
+ {storageForm.provider === 's3' && (
+ <div className="storage-provider-config">
+ <h4>S3-Compatible Storage</h4>
+ <div className="form-row">
+ <div className="form-group">
+ <label>Bucket Name</label>
+ <input
+ type="text"
+ value={storageForm.s3.bucket}
+ onChange={(e) => setStorageForm({...storageForm, s3: {...storageForm.s3, bucket: e.target.value}})}
+ placeholder="my-backup-bucket"
+ required
+ />
+ </div>
+ <div className="form-group">
+ <label>Region</label>
+ <input
+ type="text"
+ value={storageForm.s3.region}
+ onChange={(e) => setStorageForm({...storageForm, s3: {...storageForm.s3, region: e.target.value}})}
+ placeholder="us-east-1"
+ />
+ </div>
+ </div>
+ <div className="form-row">
+ <div className="form-group">
+ <label>Access Key</label>
+ <input
+ type="text"
+ value={storageForm.s3.access_key}
+ onChange={(e) => setStorageForm({...storageForm, s3: {...storageForm.s3, access_key: e.target.value}})}
+ placeholder="AKIA..."
+ required
+ />
+ </div>
+ <div className="form-group">
+ <label>Secret Key</label>
+ <input
+ type="password"
+ value={storageForm.s3.secret_key}
+ onChange={(e) => setStorageForm({...storageForm, s3: {...storageForm.s3, secret_key: e.target.value}})}
+ required
+ />
+ </div>
+ </div>
+ <div className="form-row">
+ <div className="form-group">
+ <label>Custom Endpoint URL <span className="form-help-inline">(optional, for MinIO/Wasabi)</span></label>
+ <input
+ type="text"
+ value={storageForm.s3.endpoint_url}
+ onChange={(e) => setStorageForm({...storageForm, s3: {...storageForm.s3, endpoint_url: e.target.value}})}
+ placeholder="https://s3.example.com"
+ />
+ </div>
+ <div className="form-group">
+ <label>Path Prefix</label>
+ <input
+ type="text"
+ value={storageForm.s3.path_prefix}
+ onChange={(e) => setStorageForm({...storageForm, s3: {...storageForm.s3, path_prefix: e.target.value}})}
+ placeholder="serverkit-backups"
+ />
+ </div>
+ </div>
+ </div>
+ )}
+
+ {storageForm.provider === 'b2' && (
+ <div className="storage-provider-config">
+ <h4>Backblaze B2</h4>
+ <div className="form-row">
+ <div className="form-group">
+ <label>Bucket Name</label>
+ <input
+ type="text"
+ value={storageForm.b2.bucket}
+ onChange={(e) => setStorageForm({...storageForm, b2: {...storageForm.b2, bucket: e.target.value}})}
+ placeholder="my-backup-bucket"
+ required
+ />
+ </div>
+ <div className="form-group">
+ <label>S3-Compatible Endpoint URL</label>
+ <input
+ type="text"
+ value={storageForm.b2.endpoint_url}
+ onChange={(e) => setStorageForm({...storageForm, b2: {...storageForm.b2, endpoint_url: e.target.value}})}
+ placeholder="https://s3.us-west-004.backblazeb2.com"
+ required
+ />
+ </div>
+ </div>
+ <div className="form-row">
+ <div className="form-group">
+ <label>Application Key ID</label>
+ <input
+ type="text"
+ value={storageForm.b2.key_id}
+ onChange={(e) => setStorageForm({...storageForm, b2: {...storageForm.b2, key_id: e.target.value}})}
+ required
+ />
+ </div>
+ <div className="form-group">
+ <label>Application Key</label>
+ <input
+ type="password"
+ value={storageForm.b2.application_key}
+ onChange={(e) => setStorageForm({...storageForm, b2: {...storageForm.b2, application_key: e.target.value}})}
+ required
+ />
+ </div>
+ </div>
+ <div className="form-group">
+ <label>Path Prefix</label>
+ <input
+ type="text"
+ value={storageForm.b2.path_prefix}
+ onChange={(e) => setStorageForm({...storageForm, b2: {...storageForm.b2, path_prefix: e.target.value}})}
+ placeholder="serverkit-backups"
+ />
+ </div>
+ </div>
+ )}
+
+ {storageForm.provider !== 'local' && (
+ <>
+ <div className="form-group">
+ <label className="checkbox-label">
+ <input
+ type="checkbox"
+ checked={storageForm.auto_upload}
+ onChange={(e) => setStorageForm({...storageForm, auto_upload: e.target.checked})}
+ />
+ <span>Auto-upload new backups to remote storage</span>
+ </label>
+ </div>
+
+ <div className="form-group">
+ <label className="checkbox-label">
+ <input
+ type="checkbox"
+ checked={storageForm.keep_local_copy}
+ onChange={(e) => setStorageForm({...storageForm, keep_local_copy: e.target.checked})}
+ />
+ <span>Keep local copy after uploading</span>
+ </label>
+ </div>
+ </>
+ )}
+
+ <div className="form-actions">
+ <button type="submit" className="btn btn-primary">Save Storage Config</button>
+ {storageForm.provider !== 'local' && (
+ <button
+ type="button"
+ className="btn btn-secondary"
+ onClick={handleTestConnection}
+ disabled={testingConnection}
+ >
+ {testingConnection ? (
+ <><RefreshCw size={16} className="spinning" /> Testing...</>
+ ) : (
+ <><Check size={16} /> Test Connection</>
+ )}
+ </button>
+ )}
+ </div>
+ </form>
+ </div>
+ </div>
+ )}
+
+ {/* Settings Tab */}
{activeTab === 'settings' && (
<div className="card">
<div className="card-header">
@@ -560,6 +873,7 @@ const Backups = () => {
<div className="form-actions">
<button type="submit" className="btn btn-primary">Save Settings</button>
<button type="button" className="btn btn-secondary" onClick={handleCleanup}>
+ <Trash2 size={16} />
Run Cleanup Now
</button>
</div>
@@ -586,6 +900,7 @@ const Backups = () => {
>
<option value="application">Application</option>
<option value="database">Database Only</option>
+ <option value="files">Files / Directories</option>
</select>
</div>
@@ -618,6 +933,31 @@ const Backups = () => {
</>
)}
+ {backupForm.type === 'files' && (
+ <>
+ <div className="form-group">
+ <label>Backup Name (optional)</label>
+ <input
+ type="text"
+ value={backupForm.fileName}
+ onChange={(e) => setBackupForm({...backupForm, fileName: e.target.value})}
+ placeholder="my-config-backup"
+ />
+ </div>
+ <div className="form-group">
+ <label>File/Directory Paths (one per line)</label>
+ <textarea
+ value={backupForm.filePaths}
+ onChange={(e) => setBackupForm({...backupForm, filePaths: e.target.value})}
+ placeholder={"/etc/nginx/nginx.conf\n/var/www/mysite/config\n/home/user/.env"}
+ rows={5}
+ required
+ />
+ <span className="form-help">Enter absolute paths to files or directories to backup</span>
+ </div>
+ </>
+ )}
+
{(backupForm.type === 'database' || backupForm.includeDb) && (
<>
<div className="form-group">
@@ -712,16 +1052,30 @@ const Backups = () => {
>
<option value="application">Application</option>
<option value="database">Database</option>
+ <option value="files">Files / Directories</option>
</select>
</div>
<div className="form-group">
- <label>Target</label>
+ <label>
+ {scheduleForm.backupType === 'files'
+ ? 'Paths (comma-separated)'
+ : scheduleForm.backupType === 'database'
+ ? 'Database (format: mysql:dbname or postgresql:dbname)'
+ : 'Application Name'
+ }
+ </label>
<input
type="text"
value={scheduleForm.target}
onChange={(e) => setScheduleForm({...scheduleForm, target: e.target.value})}
- placeholder="App name or database name"
+ placeholder={
+ scheduleForm.backupType === 'files'
+ ? '/etc/nginx,/var/www/config'
+ : scheduleForm.backupType === 'database'
+ ? 'mysql:mydb'
+ : 'my-app'
+ }
required
/>
</div>
@@ -735,6 +1089,19 @@ const Backups = () => {
required
/>
</div>
+
+ {storageConfig?.provider !== 'local' && (
+ <div className="form-group">
+ <label className="checkbox-label">
+ <input
+ type="checkbox"
+ checked={scheduleForm.uploadRemote}
+ onChange={(e) => setScheduleForm({...scheduleForm, uploadRemote: e.target.checked})}
+ />
+ <span>Upload to remote storage after backup</span>
+ </label>
+ </div>
+ )}
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" onClick={() => setShowScheduleModal(false)}>
@@ -757,11 +1124,7 @@ const Backups = () => {
</div>
<div className="modal-body">
<div className="restore-warning">
- <svg viewBox="0 0 24 24" width="48" height="48">
- <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
- <line x1="12" y1="9" x2="12" y2="13"/>
- <line x1="12" y1="17" x2="12.01" y2="17"/>
- </svg>
+ <AlertTriangle size={48} />
<h3>Warning</h3>
<p>Restoring this backup will overwrite existing data. This action cannot be undone.</p>
</div>
diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js
index 1d0bd7c7..ccb69790 100644
--- a/frontend/src/services/api.js
+++ b/frontend/src/services/api.js
@@ -1232,10 +1232,17 @@ class ApiService {
return this.request('/backups/schedules');
}
- async addBackupSchedule(name, backupType, target, scheduleTime, days = null) {
+ async addBackupSchedule(name, backupType, target, scheduleTime, days = null, uploadRemote = false) {
return this.request('/backups/schedules', {
method: 'POST',
- body: { name, backup_type: backupType, target, schedule_time: scheduleTime, days }
+ body: { name, backup_type: backupType, target, schedule_time: scheduleTime, days, upload_remote: uploadRemote }
+ });
+ }
+
+ async updateBackupSchedule(scheduleId, updates) {
+ return this.request(`/backups/schedules/${scheduleId}`, {
+ method: 'PUT',
+ body: updates
});
}
@@ -1243,6 +1250,58 @@ class ApiService {
return this.request(`/backups/schedules/${scheduleId}`, { method: 'DELETE' });
}
+ async backupFiles(filePaths, name = null) {
+ return this.request('/backups/files', {
+ method: 'POST',
+ body: { paths: filePaths, name }
+ });
+ }
+
+ // Remote Storage
+ async getStorageConfig() {
+ return this.request('/backups/storage');
+ }
+
+ async updateStorageConfig(config) {
+ return this.request('/backups/storage', {
+ method: 'PUT',
+ body: config
+ });
+ }
+
+ async testStorageConnection(config = null) {
+ return this.request('/backups/storage/test', {
+ method: 'POST',
+ body: config || {}
+ });
+ }
+
+ async uploadBackupToRemote(backupPath) {
+ return this.request('/backups/upload', {
+ method: 'POST',
+ body: { backup_path: backupPath }
+ });
+ }
+
+ async verifyRemoteBackup(remoteKey, localPath) {
+ return this.request('/backups/verify', {
+ method: 'POST',
+ body: { remote_key: remoteKey, local_path: localPath }
+ });
+ }
+
+ async listRemoteBackups(prefix = null) {
+ const params = prefix ? `?prefix=${encodeURIComponent(prefix)}` : '';
+ return this.request(`/backups/remote${params}`);
+ }
+
+ async downloadRemoteBackup(remoteKey, localPath = null) {
+ return this.request('/backups/remote/download', {
+ method: 'POST',
+ body: { remote_key: remoteKey, local_path: localPath }
+ });
+ }
+
// ========================================
// Git Deployment endpoints
// ========================================
diff --git a/frontend/src/styles/pages/_backups.less b/frontend/src/styles/pages/_backups.less
index 5aad1976..8c4e6dfc 100644
--- a/frontend/src/styles/pages/_backups.less
+++ b/frontend/src/styles/pages/_backups.less
@@ -148,4 +148,76 @@
color: @text-primary;
}
}
+
+ // Remote storage stat
+ .stat-icon.cloud {
+ background: fade(@info, 10%);
+ color: @info;
+ }
+
+ // Storage provider config section
+ .storage-provider-config {
+ margin: @space-4 0;
+ padding: @space-4;
+ background: @bg-hover;
+ border-radius: @radius-md;
+ border: 1px solid @border-subtle;
+
+ h4 {
+ margin: 0 0 @space-4;
+ font-size: @font-size-base;
+ color: @text-primary;
+ }
+ }
+
+ .form-help-inline {
+ font-size: @font-size-xs;
+ color: @text-tertiary;
+ font-weight: @font-weight-normal;
+ }
+
+ // Remote status badges in backup list
+ .badge {
+ svg {
+ vertical-align: -2px;
+ margin-right: 2px;
+ }
+ }
+
+ // Text helper classes
+ .text-success {
+ color: @success;
+ }
+
+ .text-muted {
+ color: @text-tertiary;
+ }
+
+ // Spinning animation for upload/test buttons
+ .spinning {
+ animation: spin 1s linear infinite;
+ }
+
+ @keyframes spin {
+ from { transform: rotate(0deg); }
+ to { transform: rotate(360deg); }
+ }
+
+ // Textarea for file paths
+ textarea {
+ width: 100%;
+ padding: @space-2 @space-3;
+ border: 1px solid @border-subtle;
+ border-radius: @radius-md;
+ background: @bg-input;
+ color: @text-primary;
+ font-family: @font-mono;
+ font-size: @font-size-sm;
+ resize: vertical;
+
+ &:focus {
+ outline: none;
+ border-color: @accent-primary;
+ }
+ }
}
diff --git a/scripts/dev/setup-linux.sh b/scripts/dev/setup-linux.sh
old mode 100644
new mode 100755
diff --git a/scripts/dev/setup-wsl.sh b/scripts/dev/setup-wsl.sh
old mode 100644
new mode 100755
diff --git a/scripts/dev/start.sh b/scripts/dev/start.sh
old mode 100644
new mode 100755