Created
March 27, 2017 10:33
-
-
Save zeroc0d3/b74a35ce52a0f5225c906adce2cf09e5 to your computer and use it in GitHub Desktop.
Export data from sqlite3 file using bash script
This file contains hidden or 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/sh | |
################# | |
# ZeroC0D3 Team # | |
################# | |
### STEP ### | |
# 1) Download binary file "sqlite3" from | |
# https://www.sqlite.org/ | |
# 2) Extract binary "sqlite3" to your PATH_BIN | |
# 3) Set your file name in PATH_TARGET_DUMP for all schema & data | |
# 4) Set your file name in PATH_TARGET_SCHEMA for only schema | |
# 5) Set your file name in PATH_TARGET_CSV for only csv format | |
# 6) Run this script in terminal: sh export_sqlite.sh | |
PATH_BIN="/home/user/project/bin/"; | |
PATH_SOURCE=$PATH_BIN"db/sample.sqlite3"; | |
PATH_TARGET_DUMP=$PATH_BIN"dump/export_all.db"; | |
PATH_TARGET_SCHEMA=$PATH_BIN"dump/export_schema.db"; | |
PATH_TARGET_CSV=$PATH_BIN"dump/export_csv.csv"; | |
##### DUMP ALL SCHEMA & DATA ##### | |
sqlite3 $PATH_SOURCE .dump > $PATH_TARGET_DUMP; | |
echo "Done... Export all to: " $PATH_TARGET_DUMP; | |
#### DUMP SCHEMA (ONLY) ##### | |
sqlite3 $PATH_SOURCE .schema > $PATH_TARGET_SCHEMA; | |
echo "Done... Export schema (only) to: " $PATH_TARGET_SCHEMA; | |
#### DUMP TO CSV FILE ##### | |
QUERY="SELECT * FROM table"; | |
# with header | |
# sqlite3 -csv -header $PATH_SOURCE $QUERY > $PATH_TARGET_CSV; | |
# without header | |
sqlite3 -csv $PATH_SOURCE $QUERY > $PATH_TARGET_CSV; | |
echo "Done... Export csv file to: " $PATH_TARGET_CSV; | |
echo "All Done !"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will fork this.
.backup
andVACUUM INTO
deserve a look as well.