Add USB backup system with CRC32 verification

**USB Backup Features:**
- Automatic backup to multiple USB drives
- CRC32 checksum verification for data integrity
- Configurable backup paths in config.json
- Backup on write (recordings and greeting uploads)
- Corrupted backups automatically deleted
- Web interface for monitoring and testing

**Configuration:**
- Added backup section to config.example.json
- enabled: Enable/disable USB backup
- usb_paths: Array of USB mount points
- verify_crc: Enable CRC32 verification
- backup_on_write: Backup immediately after file write

**CRC32 Implementation:**
- calculate_crc32(): Compute file checksum
- 64KB chunk reading for memory efficiency
- Source and destination file verification
- Automatic cleanup of failed copies

**Backup Functions:**
- backup_file_to_usb(): Backup with verification
- get_usb_backup_status(): Check drive status
- Mount detection, write test, free space check
- Preserves directory structure on USB

**Web Interface:**
- USB Backup card with drive status display
- Green/Yellow/Red status indicators
- Free space monitoring
- Test backup button
- Real-time status refresh
- Detailed error reporting

**Integration:**
- Recordings backed up after save
- Greetings backed up after upload
- Backup results logged to console
- Non-blocking backup execution

**API Endpoints:**
- GET /api/backup/status - Drive status
- POST /api/backup/test - Test backup

**Documentation:**
- Complete USB backup guide in README
- Mount instructions for USB drives
- CRC verification explanation
- Backup directory structure
- Web interface usage guide

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-24 16:28:32 +07:00
parent 7e26373fe9
commit d07cb82772
3 changed files with 387 additions and 5 deletions

View File

@@ -12,7 +12,9 @@ A Raspberry Pi-based rotary phone system for weddings and events. Guests can pic
- **Volume Control**: Adjust playback volume with real-time slider (0-100%)
- **Multiple Message Support**: Upload and manage multiple greeting messages
- **Active Message Selector**: Choose which greeting plays when the phone is picked up
- **Extra Button Support**: Optional GPIO button to play custom sounds on demand
- **Extra Button Support**: Optional GPIO button to play custom sounds during recording
- **USB Backup**: Automatic backup to multiple USB drives with CRC32 verification
- **Data Integrity**: Every file write is verified with CRC checksums
- **HiFiBerry Support**: Optimized for HiFiBerry DAC+ADC Pro audio quality
- **Real-time Status**: Monitor phone status (on-hook/off-hook/recording)
- **Auto-refresh**: Status updates every 5 seconds
@@ -206,6 +208,73 @@ Configure a delay before the greeting plays:
- Example: 2 second delay gives time to position the phone
- Default: 0 (greeting plays immediately)
### USB Backup (Optional)
Automatically backup all recordings and greeting files to USB drives:
**Configuration** (`config.json`):
```json
{
"backup": {
"enabled": true,
"usb_paths": [
"/media/usb0",
"/media/usb1"
],
"verify_crc": true,
"backup_on_write": true
}
}
```
**Features:**
- **Multiple USB Drives**: Backup to one or more USB drives simultaneously
- **CRC32 Verification**: Every backup is verified with CRC checksum
- **Automatic Backup**: Files are backed up immediately after recording/upload
- **Integrity Check**: Corrupted backups are automatically deleted
- **Web Monitoring**: View USB drive status, free space, and test backups
**Web Interface:**
- Monitor USB drive status (mounted, writable, free space)
- Test backup functionality with one click
- View real-time backup results
- Green = Ready, Yellow = Not Writable, Red = Not Mounted
**Backup Structure:**
```
/media/usb0/
└── wedding-phone-backup/
├── recordings/
│ ├── recording_20250124_143022.wav
│ └── recording_20250124_143145.wav
└── sounds/
├── dialtone.wav
└── greeting.wav
```
**How It Works:**
1. Recording finishes or greeting uploaded
2. File saved to main storage
3. CRC32 checksum calculated for source file
4. File copied to each USB drive
5. CRC32 checksum verified on each copy
6. Corrupted copies deleted automatically
7. Success/failure logged to console
**Mount USB Drives:**
```bash
# Create mount points
sudo mkdir -p /media/usb0 /media/usb1
# Auto-mount in /etc/fstab (example)
UUID=XXXX-XXXX /media/usb0 vfat defaults,nofail 0 0
UUID=YYYY-YYYY /media/usb1 vfat defaults,nofail 0 0
# Or mount manually
sudo mount /dev/sda1 /media/usb0
sudo mount /dev/sdb1 /media/usb1
```
## File Structure
```
@@ -263,6 +332,12 @@ The `config.json` file contains all system settings:
"recordings_dir": "recordings", // Subdirectory for recordings
"sounds_dir": "sounds" // Subdirectory for greeting sounds
},
"backup": {
"enabled": true, // Enable USB backup
"usb_paths": ["/media/usb0", "/media/usb1"], // USB mount points
"verify_crc": true, // Verify backups with CRC32
"backup_on_write": true // Backup immediately after write
},
"web": {
"port": 8080, // Web interface port
"max_upload_size_mb": 50 // Max upload file size