Files
mikrotik-backup/docs/migration.md
T
2026-10-28 09:16:54 +01:00

106 lines
3.3 KiB
Markdown

# Import from the previous Python/TypeScript application
The Rust service does not perform automatic data migrations on startup. Use the explicit `import-python` command once, with the previous application stopped.
## What is imported
The importer copies supported data from:
- `users`;
- `routers`;
- `backups`;
- `operation_logs`;
- `global_settings`.
Existing IDs, password hashes, credentials, timestamps, settings, and saved language/font preferences are retained when represented by the current schema.
Every backup record must resolve to exactly one physical source file. Referenced `.rsc`, RouterOS binary backups, and SwOS backup files are copied into the new layout. Existing SHA-256 values are verified when present. The resulting report includes both `backups` and `files_copied`; for a complete import they are equal.
Files that exist in an old backup directory but have **no record in the old `backups` table** are not imported.
## Before importing
1. Stop the old application so its SQLite database and WAL/journal files are stable.
2. Choose a new/empty Rust `DATA_DIR` or `DATABASE_PATH`.
3. Keep the source installation read-only if possible.
The importer refuses to merge into an existing destination database and refuses a destination inside the source tree.
## Recommended command
```bash
./import-python.sh /srv/mikrotik-backup-old
```
Equivalent direct command after building:
```bash
./target/release/mikrotik-backup import-python \
--source /srv/mikrotik-backup-old
```
Docker Compose:
```bash
docker compose run --rm \
-v /srv/mikrotik-backup-old:/legacy:ro \
app import-python --source /legacy
```
Use the same destination volume/environment later with `docker compose up -d`.
## Source discovery
The importer reads plain path values from `.env` or `backend/.env` when available and also checks common paths from the previous application:
```text
docker-data/routeros_backup_next.db
docker-data/db/routeros_backup_next.db
storage/routeros_backup_next.db
storage/db/routeros_backup_next.db
backend/storage/routeros_backup_next.db
backend/storage/db/routeros_backup_next.db
```
If multiple databases exist, select one explicitly:
```bash
./import-python.sh /srv/mikrotik-backup-old \
--database docker-data/db/routeros_backup_next.db
```
If backup files live outside the detected data directories:
```bash
./import-python.sh /srv/mikrotik-backup-old \
--backup-root /absolute/path/to/old/backups
```
Paths supplied to `--database` and `--backup-root` may be absolute or relative to `--source`.
## Failure behavior
Import stops without publishing the new database when, for example:
- the source database is missing, ambiguous, corrupt, or is already a Rust database;
- a required source table/field is missing;
- a backup record has no matching file;
- more than one candidate file matches a backup record;
- a stored checksum does not match the source file;
- the destination database already exists.
The original source is never modified. The source SQLite database is first copied to private staging storage before records are read.
## After import
Check the JSON report. In particular:
```json
{
"backups": 152,
"files_copied": 152
}
```
Then start the Rust application with the same destination configuration and verify at least one device connection, one text export, one binary/SwOS backup, and file download.