Skip to content

Instantly share code, notes, and snippets.

@juev
Created Jul 15, 2021
Embed
What would you like to do?
convert.sh -- bash script for convert postgresdb dump file to sqlite database
#!/bin/bash
FILE=$1
SQLITE=$2
if [ -z $1 ]; then
echo "convert.sh -- convert postgresdb dump to sqlite database."
echo ""
echo "First argument is dump file"
echo "Second argument is sqlite filename (optional, default value is \`sqlite.db')."
echo ""
echo "Example: $ convert.sh dump.sql sqlite.db"
exit 1
fi
if [ -z $2 ]; then
SQLITE=sqlite.db
fi
echo "Creating backup file..."
cp "$FILE" "$FILE".backup
echo "Parsing dump file..."
sed -i'' 's/true/"t"/g' $FILE
sed -i'' 's/false/"f"/g' $FILE
sed -i'' 's/"public".//g' $FILE
sed -i'' 's/SET/-- SET/g' $FILE
sed -i'' 's/SELECT setval/-- SELECT setval/g' $FILE
sed -i'' '1 i BEGIN;' $FILE
echo "END;" >> $FILE
echo ""
echo "Creating sqlite database..."
sqlite3 $SQLITE < $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment