Files
havline-native/havline/cmd/migrate_legacy.sh
T

38 lines
879 B
Bash

#!/bin/bash
set -euo pipefail
migrate_legacy_data() {
local legacy_root="$TRIM_PKGVAR/data"
local legacy_db="$legacy_root/havline.db"
local target_db="$TRIM_PKGVAR/havline.db"
if [ ! -f "$legacy_db" ] || [ -f "$target_db" ]; then
return 0
fi
echo "检测到旧版数据布局:$legacy_root"
mkdir -p "$TRIM_PKGVAR/backups"
for item in "$legacy_root"/* "$legacy_root"/.[!.]* "$legacy_root"/..?*; do
[ -e "$item" ] || continue
local name
name="$(basename "$item")"
if [ -e "$TRIM_PKGVAR/$name" ]; then
continue
fi
mv "$item" "$TRIM_PKGVAR/$name"
done
echo "旧版数据已迁移到:$TRIM_PKGVAR"
}
backup_database() {
local db="$TRIM_PKGVAR/havline.db"
if [ ! -f "$db" ]; then
return 0
fi
mkdir -p "$TRIM_PKGVAR/backups"
cp -f "$db" "$TRIM_PKGVAR/backups/havline-pre-upgrade-$(date +%Y%m%d%H%M%S).db"
}