Backup & Restore
The Backup & Restore page provides comprehensive data protection for your GEM installation, including local backups, automatic scheduling, offsite replication, and database maintenance.
Overview
GEM backups include:
- Complete database (configuration, programming, history)
- Device scripts and drivers
- UI configurations and themes
- User accounts and permissions
- System settings and attributes
Critical: Backups are encrypted. Always download and securely store your encryption keys.
Encryption Keys
Why Encryption Keys Matter
GEM uses AES-256-GCM encryption to protect sensitive data in backups:
- Passwords and API keys
- User credentials
- Private keys and certificates
- Custom secure attributes
Without the encryption keys, backups cannot be decrypted.
Downloading Encryption Keys
The page prominently displays an encryption key warning banner:
First Time (Red Warning):
- "Encryption Keys Required!" banner
- Critical warning that backups cannot be decrypted without keys
- Download Keys button (red)
After Download (Green Confirmation):
- "Encryption Keys Backed Up" banner
- Shows last download date
- Download Again button (green) - get a fresh copy anytime
- Collapse button (×) - Reduces the banner to a compact pill after confirming you've stored the keys. Click the expand icon on the pill to bring back the full banner at any time. The full warning always shows until keys have been downloaded at least once.
To Download Keys:
- Click Download Keys button in the warning banner
- A JSON file (
gem-encryption-keys-YYYY-MM-DD.json) downloads - Store this file securely:
- Password manager (1Password, LastPass, Bitwarden)
- Encrypted cloud storage (encrypted Google Drive, Dropbox folder)
- Physical safe or secure location
- Never store with backups - keep separately for security
Importing Encryption Keys
Required when restoring backups to new hardware or after system reinstall.
- Click "Need to restore a backup from a previous installation?"
- The import section expands
- Click Choose File and select your encryption keys JSON file
- Click Import Keys
- System updates to use the imported keys
- You can now restore backups from the previous installation
Important: Importing keys overwrites your current encryption keys. This is intentional - it allows your new system to decrypt backups from the old system.
Local Backups
Viewing Backups
The backup list shows all available local backups:
- Filename - Auto-generated:
gem-backup-YYYY-MM-DD-HHMMSS.tar.gz - Date - Creation timestamp
- Size - Compressed backup size
Backups are sorted newest-first.
Creating a Backup
- Click Create Backup button
- Progress modal shows creation status
- Backup appears in the list when complete
Creation Time: Typically 5-30 seconds depending on database size.
What's Included:
- Full PostgreSQL database dump
- Device scripts from
lib/user_drivers/ - Custom configuration files
- Encryption metadata
What's Excluded:
- System logs (separate retention policy)
- Temporary files
- Node modules and application code (reinstalled from source)
Downloading a Backup
- Click Download button next to any backup
- Browser downloads the
.tar.gzfile - Store offsite for disaster recovery
Use Cases:
- Offsite storage (separate from GEM server)
- Pre-upgrade snapshot
- Archival before major changes
- Migration to new hardware
Restoring a Backup
- Click Restore button next to the backup
- Confirmation dialog warns this is irreversible
- Click Yes, Restore to proceed
- Progress modal shows restore status
- System automatically reloads when complete
Restore Process:
- System disconnects all clients
- Database is dropped and recreated
- Backup is decompressed and imported
- Services restart
- Browser reloads automatically
Important: Restore replaces ALL current data. Create a backup of current state first if needed.
Deleting a Backup
- Click the Delete button (🗑️) next to any backup
- Confirm deletion
- Backup file is permanently removed
Auto-Backup
Configure automatic scheduled backups:
Enable Auto-Backup
Toggle Enable Auto-Backup to activate scheduled backups.
Schedule Options
- Hourly - Every hour on the hour
- Daily - Every day at 2:00 AM
- Weekly - Every Sunday at 2:00 AM
- Monthly - First day of month at 2:00 AM
Times use server's local timezone.
Max Backups
Set the maximum number of backups to retain (local and offsite):
- Default: 10
- Range: 1-100
- Oldest backups are deleted when limit is exceeded
Example: With max_backups=10 and daily schedule:
- Day 1-10: Accumulates backups
- Day 11+: Deletes oldest, keeps newest 10
Saving Settings
Click Save All Settings at the bottom of the page to apply changes.
Cloud Disaster Recovery
In addition to user-configured offsite backups, GEM automatically pushes a single nightly backup to updates.mygem.us for disaster recovery. This is on by default and runs every night at 3:00 AM as an independent safety net — it does not require auto-backup to be enabled.
Toggle Cloud Disaster Recovery in the Auto-Backup section to opt in or out.
:::warning Turning it off deletes the cloud copy
If you save settings with Cloud DR off after it was previously on, GEM asks updates.mygem.us to permanently delete your existing cloud backup. The page shows an inline warning before save so you don't lose this safety net by accident. If you ever need to restore from that copy in the future, leave the toggle on.
:::
How it works
- Reuses recent backup when available — if a local encrypted backup was created within the last 24 hours (e.g. by the 2 AM auto-backup), the DR job uploads that file
- Otherwise creates a temporary backup — when auto-backup is disabled or no recent backup exists, the DR job creates a backup, pushes it, then deletes the local copy so disk usage stays minimal for installs that haven't opted into local retention
- Single slot per installation — overwritten on each push, sized to your most recent backup
- Authenticated — uses the same Ed25519 client-signature scheme as license checks (signed with your installation's private key)
- Server-side decryptable — the DR endpoint uses your
installation_idas the key index so you can recover a backup even if you've lost the local copy and your encryption keys file - Skipped in development mode (
NODE_ENV=development)
:::warning Recovery key The recovery key is your installation ID. Without it, the cloud copy cannot be restored. Keep it safe alongside your encryption keys. :::
Cloud Disaster Recovery is a safety net, not a replacement for offsite backups you control. It exists so a fresh-install + DR pull can recover a lost site without third-party storage. For routine offsite redundancy use SFTP, S3, or SMB below.
Offsite Backup
Protect against hardware failure by replicating backups to remote storage.
Provider Selection
Choose offsite provider:
- None (Local Only) - No offsite backup
- SFTP - Secure FTP to your own server
- S3-Compatible - Cloud object storage (AWS S3, Backblaze B2, MinIO, Wasabi, etc.)
- SMB/CIFS - Windows/Samba network share
SFTP Backup
Replicate backups to any SFTP server (NAS, VPS, dedicated server).
Configuration
Enable SFTP Backup: Toggle to activate
Connection Settings:
- Host - SFTP server hostname or IP
- Port - SSH port (default: 22)
- Username - SSH username
- Remote Path - Destination directory (e.g.,
/backups/gem/)
Authentication Method (tabs):
Password Authentication:
- Password - SSH password (encrypted)
SSH Key Authentication:
- Private Key - Paste OpenSSH private key
-----BEGIN OPENSSH PRIVATE KEY-----b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAA...-----END OPENSSH PRIVATE KEY-----
- Passphrase - Key passphrase if encrypted (optional)
Options:
- Auto-upload - Automatically upload new backups after creation
Testing Connection
- Fill in connection settings
- Click Test Connection
- Result shows: ✅ Connection successful! or ❌ Error message
Test before enabling to verify configuration.
Sync Now
Click Sync Now to immediately:
- Upload all local backups not on remote server
- Download remote backups not on local server
- Respect max_backups limit
- Remove excess old backups
Remote Backups
Click List Remote Backups to:
- View all backups on SFTP server
- Download specific backups
- Restore directly from remote
- Delete remote backups
Remote Backup Actions:
- Download - Copy to local storage
- Restore - Download and restore in one step
- Delete - Permanently remove from remote server
S3-Compatible Backup
Replicate backups to any S3-compatible cloud storage service.
Supported Providers
| Provider | Endpoint Required | Notes |
|---|---|---|
| Amazon S3 | No (uses default) | Standard AWS S3 |
| Backblaze B2 | Yes | Use S3-compatible API endpoint; region must match bucket |
| Wasabi | Yes (pre-filled) | Hot storage, no egress fees |
| MinIO | Yes | Self-hosted; enable Force Path Style |
| Other | Yes | Any S3-compatible API |
:::note Migrating from Backblaze B2 If you previously used the B2-specific integration, GEM automatically migrates your configuration to the S3-compatible format on startup. You will need to set the Endpoint and Region from your Backblaze bucket settings before auto-upload will work. :::
Configuration
Enable S3 Backup: Toggle to activate
Provider: Select your storage provider. This pre-fills the endpoint and adjusts guidance.
Credentials:
- Access Key ID - S3 access key (IAM user for AWS, Application Key ID for B2)
- Secret Access Key - S3 secret key (encrypted)
- Bucket - Target bucket name
Connection:
- Endpoint - Provider's S3 API URL (not needed for AWS)
- Region - Bucket region (e.g.,
us-east-1) - Remote Path Prefix - Organize by installation (e.g.,
backups/) - Force Path Style - Enable for MinIO and some self-hosted providers
Options:
- Auto-upload - Automatically upload new backups after creation
Testing Connection
- Fill in credentials and bucket info
- Click Test Connection
- Result shows: ✅ Connection successful with bucket details or ❌ Error
Sync Now
Click Sync Now to upload/download backups and enforce max_backups limit.
Remote Backups
Click List Remote Backups to view, download, restore, or delete S3-stored backups.
SMB/CIFS Backup
Replicate backups to a Windows or Samba network share (NAS devices, Windows servers, etc.).
:::warning Requirement
The smbclient package must be installed on the GEM server. Install with: sudo apt install smbclient
:::
Configuration
Enable SMB Backup: Toggle to activate
Connection Settings:
- Host - Server hostname or IP address (e.g.,
192.168.1.100ornas.local) - Share Name - Network share name (e.g.,
Backups) - Username - Login username
- Password - Login password (encrypted)
- Domain - Windows domain or workgroup (optional, e.g.,
WORKGROUP) - Remote Path - Directory within the share (default:
/gem/)
Options:
- Auto-upload - Automatically upload new backups after creation
Testing Connection
- Fill in connection settings
- Click Test Connection
- Result shows: ✅ Connection successful or ❌ Error with details
Sync Now
Click Sync Now to upload local backups to the share and enforce max_backups limit.
Remote Backups
Click List Remote Backups to view, download, restore, or delete SMB-stored backups.
Offsite Backup Best Practices
-
3-2-1 Rule: 3 copies, 2 different media, 1 offsite
- Local: On GEM server
- SFTP or SMB: Network-attached storage
- S3: Cloud storage
-
Test Restores: Periodically verify backup integrity by restoring to a test system
-
Multiple Destinations: Use both local network (SFTP/SMB) and cloud (S3) for redundancy
-
Monitoring: Check sync success regularly (setup monitoring alerts)
-
Encryption: Backups are encrypted before upload - keep keys separate
-
Bandwidth: Consider bandwidth for initial upload and daily syncs
Database Maintenance
Automatically clean old historical data to maintain performance.
Configuration
Enable Auto-Maintenance: Toggle to activate
Retention Period: Days to keep data (default: 90)
What Gets Cleaned
Database maintenance removes old records from:
- Attribute History - Historical attribute value changes
- Request History - API and command logs
- Access Log - User login and access events
Not Affected:
- Current configuration (devices, zones, macros, etc.)
- User accounts
- Programming
- Current attribute values
Running Maintenance
Automatic: Runs daily at 3:00 AM (server time) when enabled
Manual: Click Run Maintenance Now to execute immediately
Result Display:
✅ Maintenance complete! Deleted 15,234 old records:
• 10,456 attribute history
• 3,891 request history
• 887 access log
Retention Guidelines
Recommended Settings:
- Production Systems: 90-180 days
- High-Traffic Systems: 30-60 days
- Compliance Requirements: Per regulation (may be 1-7 years)
- Development Systems: 7-30 days
Performance Impact:
- 1M+ records: Noticeable slowdown on queries
- 10M+ records: Significant performance degradation
- Regular maintenance prevents accumulation
Backup Scenarios
Pre-Upgrade Backup
Before upgrading GEM:
- Create a manual backup
- Download the backup file
- Store separately from server
- Perform upgrade
- If issues occur, restore backup
Migration to New Hardware
-
On old system:
- Create a backup
- Download encryption keys
- Download the backup file
-
On new system:
- Install GEM
- Import encryption keys
- Upload or restore backup
- Verify all functionality
Disaster Recovery
- Install GEM on new hardware
- Import encryption keys
- Restore backup from:
- Downloaded backup file (upload manually)
- SFTP server (list & restore)
- S3 cloud storage (list & restore)
- SMB network share (list & restore)
- Verify system operation
- Update network-dependent configuration (IP addresses, etc.)
Regular Archival
For long-term archival:
- Enable auto-backup with appropriate schedule
- Configure offsite backup (SFTP or B2)
- Periodically download backups for offline storage
- Document backup dates and encryption key location
- Test restore process annually
Troubleshooting
Backup Creation Fails
Symptoms: Backup creation hangs or shows error
Causes:
- Insufficient disk space
- Database connection timeout
- File permission issues
Solutions:
- Check free disk space:
df -h - Verify PostgreSQL is running:
systemctl status postgresql - Check backup directory permissions
- Review logs: Insights > Logging
Restore Fails
Symptoms: Restore process errors or hangs
Causes:
- Corrupted backup file
- Mismatched encryption keys
- PostgreSQL version mismatch
- Insufficient disk space
Solutions:
- Verify backup file integrity (try downloading again)
- Confirm encryption keys are correct
- Check PostgreSQL version compatibility
- Ensure adequate free space
- Check logs for specific error messages
SFTP Connection Fails
Symptoms: ❌ Connection failed error
Common Issues:
- Wrong Credentials: Double-check username/password
- Key Format: Ensure private key is OpenSSH format (not PuTTY .ppk)
- Firewall: Verify port 22 (or custom port) is open
- Permissions: Remote path must be writable
- Host Key: Some servers require host key verification
Debugging:
- Test connection from command line:
sftp username@host - Verify path exists and is writable
- Check SSH server logs on remote system
S3 Connection Fails
Symptoms: ❌ Connection failed error
Common Issues:
- Invalid Credentials: Verify access key ID and secret access key
- Bucket Not Found: Confirm the bucket name is correct and exists
- Wrong Endpoint/Region: For non-AWS providers, the endpoint and region must match your bucket configuration
- Permission Denied: Ensure the credentials have read/write access to the bucket
- Network Issues: Verify internet connectivity
Provider-Specific Tips:
- Backblaze B2: The endpoint region (e.g.,
us-west-004) must match the bucket's region. Find this in your B2 bucket settings. - MinIO: Enable Force Path Style in configuration
- AWS: Ensure IAM user has
s3:GetObject,s3:PutObject,s3:DeleteObject, ands3:ListBucketpermissions
SMB Connection Fails
Symptoms: ❌ Connection failed error
Common Issues:
- smbclient Not Installed: Install with
sudo apt install smbclient - Login Failed: Double-check username and password; try including the domain
- Share Not Found: Verify the share name matches exactly (case-sensitive)
- Host Unreachable: Verify the host address and that SMB ports (445) are accessible
- Remote Path Not Found: The directory within the share may not exist yet (GEM will try to create it)
Debugging:
- Test from command line:
smbclient '//host/share' -U 'username' - Verify share is accessible from the GEM server's network
Encryption Key Issues
Lost Keys: Cannot decrypt backups without keys - prevention is critical
Wrong Keys: Importing wrong keys will cause restore to fail with decryption errors
Backup Keys: Always have multiple secure copies:
- Primary: Password manager
- Secondary: Encrypted cloud storage
- Tertiary: Printed hardcopy in physical safe
Security Considerations
-
Key Storage: Never store encryption keys in the same location as backups
-
Access Control: Limit who can download backups and keys
-
Network Security: Use SSH key authentication for SFTP when possible
-
Cloud Security: Use application-specific keys for S3 providers, not master/root keys
-
Audit Trail: Monitor access to Backup & Restore page
-
Testing: Regularly test restore process to ensure business continuity
-
Offsite: Always maintain offsite backups for disaster recovery
Related Documentation
- Attributes - Understanding encrypted attributes
- Logging - Viewing backup/restore logs
- Data Retention - Managing historical data
- Server - SSL/TLS certificate backup considerations