Skip to content

Instantly share code, notes, and snippets.

@amackiewicz
Created October 21, 2020 14:58
Show Gist options
  • Save amackiewicz/66a19f50e247a0224110a846bf2e4a84 to your computer and use it in GitHub Desktop.
Save amackiewicz/66a19f50e247a0224110a846bf2e4a84 to your computer and use it in GitHub Desktop.
export data from sqlite3 database file and import to remote pgsql
SOURCE_SQLITE_PATH=$(pwd)/db.sqlite SOURCE_TABLE_NAME=? PSQL_TARGET_HOST=? PSQL_TARGET_DB=? PSQL_TARGET_USER=? PSQL_TARGET_PASS=? docker run --rm -v ${SOURCE_SQLITE_PATH}:/root/db/db.sqlite -v $(pwd)/output.sql:/root/db/output.sql --name sqlite3-export nouchka/sqlite3:latest db\.sqlite .mode\ insert select\ *\ from\ ${SOURCE_TABLE_NAME} > output.sql && docker run --rm -v $(pwd)/output.sql:/dev/shm/inserts.sql -env PGPASSWORD=${PSQL_TARGET_PASS} --name pgsql-import postgres:12.1-alpine psql -h ${PSQL_TARGET_HOST} -U ${PSQL_TARGET_USER} ${PSQL_TARGET_DB} < /dev/shm/inserts.sql && rm output.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment