Migration - UNITRONIX/BetterDesk GitHub Wiki
BetterDesk provides migration tools for moving between databases and from legacy RustDesk deployments.
The migration tool supports 5 modes:
| Mode | Source | Target | Description |
|---|---|---|---|
rust2go |
RustDesk Rust db_v2.sqlite3
|
BetterDesk Go SQLite | Migrate from original RustDesk server |
sqlite2pg |
BetterDesk Go SQLite | PostgreSQL | Move to PostgreSQL for production |
pg2sqlite |
PostgreSQL | BetterDesk Go SQLite | Reverse migration for backup/testing |
nodejs2go |
Node.js console SQLite | BetterDesk Go SQLite | Merge Node.js console data |
backup |
Any SQLite | SQLite copy | Create timestamped backup |
The simplest way to migrate:
# Linux
sudo ./betterdesk.sh
# Choose option M — Migrate databases
# Windows
.\betterdesk.ps1
# Choose option M — Migrate databasesThe script:
- Detects current database configuration
- Offers available migration paths
- Creates automatic backup before migration
- Runs the migration tool
- Updates
.envand service files - Restarts services
# Linux
./betterdesk-server/tools/migrate/migrate-linux-amd64
# Or compile from source
cd betterdesk-server/tools/migrate
go build -o migrate ../migrate -mode <mode> -src <source> -dst <destination> [options]./migrate -mode rust2go \
-src /path/to/rustdesk/db_v2.sqlite3 \
-dst /opt/rustdesk/db_v2.sqlite3This handles schema differences:
-
peertable →peerstable - Column name mapping
- UUID generation for entries without UUIDs
./migrate -mode sqlite2pg \
-src /opt/rustdesk/db_v2.sqlite3 \
-dst "postgres://betterdesk:password@localhost:5432/betterdesk?sslmode=disable"Migrated data:
- All peers with status, tags, notes
- Users with roles and TOTP config
- API keys
- Server config
- Audit log entries
- Address books
- Access policies
./migrate -mode pg2sqlite \
-src "postgres://betterdesk:password@localhost:5432/betterdesk" \
-dst /opt/rustdesk/db_v2.sqlite3Useful for creating portable backups or moving to a smaller deployment.
./migrate -mode nodejs2go \
-src /opt/BetterDeskConsole/data/auth.db \
-dst /opt/rustdesk/db_v2.sqlite3 \
-node-auth /opt/BetterDeskConsole/data/auth.dbMerges:
-
peertable →peers -
userstable →users - Folder assignments
- Tags
The migration tool preserves:
| Data | rust2go | sqlite2pg | pg2sqlite | nodejs2go |
|---|---|---|---|---|
| Peers | ✅ | ✅ | ✅ | ✅ |
| Ed25519 keys | ✅ | ✅ | ✅ | N/A |
| UUIDs | ✅ (generated) | ✅ | ✅ | ✅ (generated) |
| ID history | ✅ | ✅ | ✅ | N/A |
| Bans | ✅ | ✅ | ✅ | N/A |
| Tags | ✅ | ✅ | ✅ | ✅ |
| Notes | N/A | ✅ | ✅ | ✅ |
| Users | N/A | ✅ | ✅ | ✅ |
| API keys | N/A | ✅ | ✅ | N/A |
| Audit log | N/A | ✅ | ✅ | N/A |
| Address books | N/A | ✅ | ✅ | N/A |
| Access policies | N/A | ✅ | ✅ | N/A |
./betterdesk-docker.sh
# Choose option M — Migrate from RustDesk DockerThe script:
- Detects existing RustDesk containers and volumes
- Copies
db_v2.sqlite3andid_ed25519from old volumes - Runs
rust2gomigration - Creates BetterDesk containers with migrated data
./betterdesk-docker.sh
# Choose option P — Migrate to PostgreSQLAdds a PostgreSQL container, runs sqlite2pg migration, and updates services.
If you're running the original RustDesk hbbs+hbbr:
sudo systemctl stop rustdesksignal rustdeskrelay
# or
sudo systemctl stop hbbs hbbrsudo ./betterdesk.sh
# Choose option 1 — New installationsudo ./betterdesk.sh
# Choose option M — Migrate databases
# Select "Rust → Go" migration# Check device count
curl http://localhost:21114/api/server/stats
# Verify in web console
open http://localhost:5000# Remove old services (the installer does this automatically)
sudo systemctl disable rustdesksignal rustdeskrelay
sudo rm /etc/systemd/system/rustdesk*.serviceAlways create a backup before migrating:
# Using the installer
sudo ./betterdesk.sh
# Choose option 5 — Backup
# Manual backup
cp /opt/rustdesk/db_v2.sqlite3 /opt/rustdesk/db_v2.sqlite3.backup
cp /opt/BetterDeskConsole/data/auth.db /opt/BetterDeskConsole/data/auth.db.backup# If Go is installed, compile from source
cd betterdesk-server/tools/migrate
go build -o migrate .The installer checks if the binary supports the -mode flag. If not:
# Rebuild
cd betterdesk-server/tools/migrate
go build -o migrate .# Check PostgreSQL is running
sudo systemctl status postgresql
# Test connection
psql "postgres://betterdesk:password@localhost:5432/betterdesk"
# Check firewall
sudo ufw allow 5432/tcpIf migrating to a database that already has data, the migration tool uses INSERT OR IGNORE (SQLite) or ON CONFLICT DO NOTHING (PostgreSQL) to skip duplicates.