|
|
@@ -2806,6 +2806,10 @@ postgresql_menu() {
|
|
|
esac
|
|
|
}
|
|
|
|
|
|
+# Convert between the panel's SQLite database and a portable .dump (SQL text)
|
|
|
+# file using the bundled x-ui binary. With no arguments it dumps the installed
|
|
|
+# panel database; an optional second argument overrides the output path.
|
|
|
+# x-ui migrateDB [file.db|file.dump] [output]
|
|
|
migrate_db() {
|
|
|
local input="$1" output="$2"
|
|
|
local default_db="/etc/x-ui/x-ui.db"
|
|
|
@@ -2818,9 +2822,15 @@ migrate_db() {
|
|
|
return 1
|
|
|
fi
|
|
|
|
|
|
+ if ! "$bin" migrate-db -h 2>&1 | grep -q -- '-dump'; then
|
|
|
+ LOGE "This x-ui build does not support .db <-> .dump conversion yet."
|
|
|
+ LOGE "Update the panel first (x-ui update) to a version with 'migrate-db --dump/--restore'."
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+
|
|
|
if [[ ! -f "$input" ]]; then
|
|
|
LOGE "Input file not found: ${input}"
|
|
|
- echo -e "Usage: ${green}x-ui migrateDB <file.db|file.dump> [output]${plain}"
|
|
|
+ echo -e "Usage: ${green}x-ui migrateDB [file.db|file.dump] [output]${plain}"
|
|
|
return 1
|
|
|
fi
|
|
|
|
|
|
@@ -2843,6 +2853,9 @@ migrate_db() {
|
|
|
|
|
|
if [[ "$mode" == "dump" ]]; then
|
|
|
[[ -z "$output" ]] && output="${input%.*}.dump"
|
|
|
+ if [[ -f "$output" ]]; then
|
|
|
+ confirm "Output ${output} already exists and will be overwritten. Continue?" "n" || return 0
|
|
|
+ fi
|
|
|
LOGI "Dumping SQLite database to SQL text:"
|
|
|
echo -e " ${green}${input}${plain} -> ${green}${output}${plain}"
|
|
|
if "$bin" migrate-db --src "$input" --dump "$output"; then
|
|
|
@@ -2853,6 +2866,11 @@ migrate_db() {
|
|
|
fi
|
|
|
else
|
|
|
[[ -z "$output" ]] && output="${input%.*}.db"
|
|
|
+ if [[ "$output" == "$default_db" ]] && check_status > /dev/null 2>&1; then
|
|
|
+ LOGE "Refusing to restore into the live database (${default_db}) while x-ui is running."
|
|
|
+ LOGE "Stop the panel first (x-ui stop) or choose a different output path."
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
if [[ -f "$output" ]]; then
|
|
|
confirm "Output ${output} already exists and will be overwritten. Continue?" "n" || return 0
|
|
|
rm -f "$output"
|
|
|
@@ -2898,7 +2916,7 @@ show_usage() {
|
|
|
│ ${blue}x-ui banlog${plain} - Check Fail2ban ban logs │
|
|
|
│ ${blue}x-ui update${plain} - Update │
|
|
|
│ ${blue}x-ui update-all-geofiles${plain} - Update all geo files │
|
|
|
-│ ${blue}x-ui migrateDB <file>${plain} - Convert .db <-> .dump (SQLite) │
|
|
|
+│ ${blue}x-ui migrateDB [file]${plain} - Convert .db <-> .dump (SQLite) │
|
|
|
│ ${blue}x-ui legacy${plain} - Legacy version │
|
|
|
│ ${blue}x-ui install${plain} - Install │
|
|
|
│ ${blue}x-ui uninstall${plain} - Uninstall │
|