mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-05 12:44:22 +00:00
fix(x-ui.sh): address review feedback on migrateDB
Per Copilot review on PR #4910: - Probe the bundled binary for migrate-db --dump support and fail with a clear upgrade message instead of a raw "flag not defined" error on old builds. - Prompt before overwriting an existing .dump in dump mode (parity with restore). - Refuse to restore into the live database path while x-ui is running, to avoid corrupting the running panel. - Fix the usage/synopsis strings to show input is optional ([file] not <file>).
This commit is contained in:
parent
e3deac536f
commit
5dd506d255
1 changed files with 20 additions and 2 deletions
22
x-ui.sh
22
x-ui.sh
|
|
@ -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 │
|
||||
|
|
|
|||
Loading…
Reference in a new issue