Backup UI Integration
Backup UI Integration - Complete Implementation
What Was Implemented
1. API Endpoints
BackupController now includes:
GET /api/backup/config- Get current backup configurationPUT /api/backup/config- Update backup configuration (saves to appsettings.json)POST /api/backup/trigger- Trigger manual backup immediatelyGET /api/backup/list- List all existing backups with detailsDELETE /api/backup/{name}- Delete a specific backup
2. BackupHostedService Enhancement
- Added
TriggerManualBackupAsync()public method - Added semaphore to prevent concurrent backups
- Manual backups can now be triggered without waiting for the schedule
3. BedrockApiService Updates
Added methods for backup management:
- GetBackupConfigAsync()
- UpdateBackupConfigAsync(frequency, directory, maxBackups)
- TriggerManualBackupAsync()
- GetBackupListAsync()
- DeleteBackupAsync(backupName)
4. PublicUI - Backup Settings Page
Complete overhaul of the Backup Settings page with:
Configuration Management:
- Load settings from API on page load
- Edit frequency (1-1440 minutes)
- Edit backup directory path
- Edit max backups to keep (0 = unlimited)
- Save settings to API (updates appsettings.json)
- Restart warning after saving settings
Manual Backup:
- "Backup Now" button to trigger immediate backup
- Status feedback during backup operation
- Auto-refresh backup list after manual backup
Backup Management:
- View list of existing backups
- Display name, creation date, and size
- Refresh button to reload backup list
- Delete individual backups with confirmation
User Experience:
- Loading indicators for all operations
- Status messages with color coding
- Disabled buttons during operations
- Helpful information section
- Current settings display
UI Features
Backup Configuration Card
Backup Configuration
Backup Frequency: [30] minutes
Output Directory: [C:\Backups\...]
Maximum Backups: [10]
[Save Settings]
[Backup Now]
Existing Backups Card
Existing Backups [Refresh]
Name Created Size
backup_2025... Jan 15 45.3MB
backup_2025... Jan 15 44.9MB
Total: 2 backup(s)
User Workflow
Edit Settings
- User opens Backup Settings page
- Settings are loaded from API
- User edits frequency, directory, or max backups
- User clicks "Save Settings"
- Settings are saved to appsettings.json
- UI shows success message with restart warning
Trigger Manual Backup
- User clicks "Backup Now" button
- API triggers BackupHostedService.TriggerManualBackupAsync()
- Backup process runs in background
- UI shows status message
- Backup list auto-refreshes after 3 seconds
View Backups
- User views existing backups in table
- Can see name, creation date, and size
- Click "Refresh" to reload list
- Click "Delete" to remove a backup (with confirmation)
Technical Details
Configuration Update Flow
PublicUI
(PUT /api/backup/config)
BackupController
(Update file)
appsettings.json
(Restart required)
BackupHostedService (reads new config)
Manual Backup Flow
User clicks "Backup Now"
BedrockApiService.TriggerManualBackupAsync()
(POST /api/backup/trigger)
BackupController
BackupHostedService.TriggerManualBackupAsync()
(Semaphore prevents concurrent backups)
PerformBackupAsync()
Backup created
Concurrency Protection
The semaphore ensures:
- Only one backup runs at a time
- Manual backups don't conflict with scheduled backups
- Returns false if backup already in progress
API Response Examples
GET /api/backup/config
Response:
{
"frequencyMinutes": 30,
"backupDirectory": "C:\\Backups\\Minecraft",
"maxBackupsToKeep": 10
}
PUT /api/backup/config
Request:
{
"frequencyMinutes": 60,
"backupDirectory": "D:\\ServerBackups",
"maxBackupsToKeep": 20
}
Response:
{
"message": "Configuration updated successfully. Restart the API for changes to take effect.",
"restartRequired": true,
"config": {
"frequencyMinutes": 60,
"backupDirectory": "D:\\ServerBackups",
"maxBackupsToKeep": 20
}
}
POST /api/backup/trigger
Response (Success):
{
"message": "Manual backup has been triggered successfully.",
"note": "Check the API logs for backup progress and completion."
}
Response (Already Running):
{
"error": "A backup is already in progress",
"message": "Please wait for the current backup to complete before triggering another."
}
GET /api/backup/list
Response:
{
"backups": [
{
"name": "backup_2025-01-15_14-30-00",
"createdAt": "2025-01-15T14:30:00",
"sizeMB": 45.3,
"path": "C:\\Backups\\Minecraft\\backup_2025-01-15_14-30-00"
},
{
"name": "backup_2025-01-15_14-00-00",
"createdAt": "2025-01-15T14:00:00",
"sizeMB": 44.9,
"path": "C:\\Backups\\Minecraft\\backup_2025-01-15_14-00-00"
}
],
"count": 2
}
DELETE /api/backup/
Response:
{
"message": "Backup 'backup_2025-01-15_14-00-00' deleted successfully"
}
Important Notes
Restart Required
After updating configuration via the UI:
- Settings are saved to
appsettings.json - The API must be restarted for changes to take effect
- The UI displays a clear warning about this
Validation
All settings are validated:
- Frequency: 1-1440 minutes
- Directory: Must not be empty
- Max Backups: 0 or greater (0 = unlimited)
Security
- Backup name validation prevents directory traversal attacks
- No arbitrary file system access
- Confirmation required before deleting backups
Use Cases
Use Case 1: Admin Changes Backup Frequency
- Admin opens PublicUI
- Navigates to Backup Settings
- Changes frequency from 30 to 60 minutes
- Clicks "Save Settings"
- Sees success message with restart warning
- Restarts API
- Backups now run every 60 minutes
Use Case 2: Manual Backup Before Maintenance
- Admin needs to perform maintenance
- Opens Backup Settings
- Clicks "Backup Now"
- Waits for confirmation message
- Proceeds with maintenance knowing data is backed up
Use Case 3: Clean Up Old Backups
- Admin checks disk space
- Opens Backup Settings
- Views list of backups with sizes
- Deletes old backups individually
- Or changes "Max Backups to Keep" to auto-clean
Future Enhancements
Potential additions:
- Download backup as ZIP
- Restore from backup via UI
- Backup verification status
- Scheduled backup calendar view
- Email notifications
- Backup to cloud storage
Build Status
Build: Successful
All features: Implemented and tested
Ready for: Production use
Summary
The Backup Settings page in PublicUI is now fully integrated with the API, allowing complete management of backup configuration and operations:
- View and edit all backup settings
- Trigger manual backups on demand
- View existing backups with details
- Delete individual backups
- All operations with proper feedback
- Clean, intuitive user interface
No more manual editing of appsettings.json - everything can be managed through the UI!