Files
mikrotik-backup/import-python.sh
T
2026-10-28 09:16:54 +01:00

46 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Explicit, copy-only import from a Python/TypeScript installation into new storage.
set -euo pipefail
umask 077
usage() {
cat <<'USAGE'
Usage: ./import-python.sh SOURCE_DIRECTORY [--database PATH] [--backup-root DIRECTORY]
Import accounts, devices, settings, logs and backup files from the original
Python/TypeScript application into a new Rust installation.
Stop the original application before importing. Source files are not changed.
The destination is selected by DATA_DIR and DATABASE_PATH, as with ./start.sh.
An existing destination database is never overwritten or merged.
Examples:
./import-python.sh /srv/mikrotik-python
DATA_DIR=./storage-imported ./import-python.sh "/srv/old app"
./import-python.sh /srv/mikrotik-python --database docker-data/db/routeros_backup_next.db
The script builds the current Rust sources, runs the import, and exits.
After a successful import, run ./start.sh with the same destination settings.
See docs/migration.md for discovery rules and backup-path overrides.
USAGE
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
if [[ $# -eq 0 || -z "${1:-}" ]]; then
usage >&2
exit 2
fi
# Resolve the source before start.sh changes the working directory. Preserve
# every argument boundary, including paths containing spaces or shell metacharacters.
source_dir="$(CDPATH= cd -- "$1" && pwd -P)" || {
echo "Source directory does not exist or cannot be read: $1" >&2
exit 2
}
shift
project_dir="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
exec bash "$project_dir/start.sh" import-python --source "$source_dir" "$@"