Skip to content

Commit 706b7bd

Browse files
committed
Fix new DB load script.
In particular: - support spaces in filenames - print actual list of choices - only list files as choices, and only files with suffix .sql.gz - start indexing with 1 as this script is meant to be run by humans
1 parent 7c87858 commit 706b7bd

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

sql/dj_setup_database.in

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,29 +398,36 @@ dump)
398398
;;
399399

400400
load)
401-
choice=""
402401
DUMPNAME="$2"
402+
FILE=""
403403
if [ -z "$DUMPNAME" ]; then
404-
set -- $(ls $DATABASEDUMPDIR)
405-
ind=0
404+
databases=$(find "$DATABASEDUMPDIR" -name "*.sql.gz" -type f -print0)
405+
if [ -z "$databases" ]; then
406+
echo "No files with .sql.gz suffix found in '$DATABASEDUMPDIR'"
407+
exit 1
408+
fi
409+
ind=1
410+
for i in "$databases"; do
411+
echo "$ind) $i"
412+
: $((ind+=1))
413+
done
406414
while true; do
407415
read -p "Which database should be loaded? " db
408-
ind=0
409-
for i in $@; do
416+
ind=1
417+
for i in "$databases"; do
410418
if [ "$ind" = "$db" ]; then
411-
choice="$i"
419+
FILE="$i"
412420
break
413421
fi
414422
: $((ind+=1))
415423
done
416-
if [ -n "$choice" ]; then
424+
if [ -n "$FILE" ]; then
417425
break
418426
fi
419427
done
420428
else
421-
choice="${DUMPNAME}.sql.gz"
429+
FILE="$DATABASEDUMPDIR/${DUMPNAME}.sql.gz"
422430
fi
423-
FILE="$DATABASEDUMPDIR/${choice}"
424431

425432
if [ ! -f "${FILE}" ]; then
426433
echo "Error: file ${FILE} not found."

0 commit comments

Comments
 (0)