Created
July 15, 2021 07:25
-
-
Save juev/f4e8ca58a600bfe054378e4c0840036d to your computer and use it in GitHub Desktop.
convert.sh -- bash script for convert postgresdb dump file to sqlite database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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