From dd7b393f818fcf888f87866ddacba89f2635f506 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 3 Jun 2020 01:29:06 +0200 Subject: Rudimentary script converting MySQL dump to SQLite3 dump --- dump/.gitignore | 1 + dump/convert.sh | 15 +++++++++++++++ fetcher/fetch.sh | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 dump/.gitignore create mode 100755 dump/convert.sh diff --git a/dump/.gitignore b/dump/.gitignore new file mode 100644 index 0000000..d1b811b --- /dev/null +++ b/dump/.gitignore @@ -0,0 +1 @@ +*.sql diff --git a/dump/convert.sh b/dump/convert.sh new file mode 100755 index 0000000..2e99ef1 --- /dev/null +++ b/dump/convert.sh @@ -0,0 +1,15 @@ +#!/bin/bash +grep -E '(^(INSERT INTO|(CREATE|DROP) TABLE) )|([,;\)]$)' $1 | # throw away comments and empty lines, mainly + grep -v -E '^/\*' | # throw away comment-like directives which end in a semicolon + grep -v -E '^(UN)?LOCK TABLES' | # MySQL-specific table locks + grep -v -E '^\s+KEY' | # getting rid of non-primary key indices + sed 's/ AUTO_INCREMENT.*\([,;]\)$/\1/g' | # getting rid of auto-increments + sed 's/UNIQUE KEY[^(]*/UNIQUE/g' | # SQLite syntax of unique keys + sed 's/) DEFAULT CHARSET.*;$/);/g' | # MySQL-specific leftovers for tables without auto-increment + sed s/"\\\'"/\'\'/g | # single-quote escaped as '' instead of \' + sed -e '/,\s*$/{N;s/,\s*\n)/\n)/g;P;D}' # now, here be dragons. +# for every line ending in comma, it appends the next line to sed's buffer +# then, trims comma from end of the first line +# if the second line begins with a closing paren +# finally, prints out the first line and removes it from buffer, +# allowing to proceed to the next line diff --git a/fetcher/fetch.sh b/fetcher/fetch.sh index e083ee5..3c69567 100755 --- a/fetcher/fetch.sh +++ b/fetcher/fetch.sh @@ -15,5 +15,10 @@ if [[ f1db.sql.gz -nt f1db.sql ]]; then zcat f1db.sql.gz | sed 's/ ENGINE=MyISAM//' > f1db.sql find -name f1db.sql.gz -printf '%f: %Td-%Tm-%TY %TH:%TM, %s bytes\n' touch -r f1db.sql.gz f1db.sql + if [ "$1" == "dump" ] + then + cp f1db.sql ../dump/original.sql + ../dump/convert.sh ../dump/original.sql > ../dump/sqlite.sql + fi fi popd > /dev/null -- cgit v1.2.3