2024-01-03 00:34:39 +00:00
#!/bin/bash
DB_PATH = $( realpath " $1 " )
DUMP_PATH = $( realpath " $2 " )
SQL = "select sql||';' from sqlite_master where sql is not null order by type='table' desc, type='index' desc, type='view' desc, type='trigger' desc, name;"
read -s -p "Password (if any): " PASS; echo '' ;
if [ -z " $PASS " ] ; then
BIN_PATH = sqlite3
else
BIN_PATH = sqlcipher
fi
# dump
$BIN_PATH " $DB_PATH " <<EOF
pragma key = '$PASS' ;
.output '$DUMP_PATH'
$SQL
.output 'stdout'
EOF
# test
TEST_DB_PATH = " $DUMP_PATH .test.db "
2024-01-03 00:48:48 +00:00
rm -f " $TEST_DB_PATH "
2024-01-03 00:34:39 +00:00
cat " $DUMP_PATH " | sqlite3 " $TEST_DB_PATH "
echo 'pragma foreign_key_check;' | sqlite3 " $TEST_DB_PATH "
2024-01-03 00:48:48 +00:00
rm -f " $TEST_DB_PATH "