-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.sh
More file actions
32 lines (26 loc) · 633 Bytes
/
Copy pathexport.sh
File metadata and controls
32 lines (26 loc) · 633 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
#
# Export the STACKIT database as CSV and gzip compressed SQL dump.
#
MY_DATABASE="stackit.db"
CSV_EXPORT="stackit-instances.csv"
SQL_EXPORT="stackit.sql"
echo "Export"
echo -e "\tSQL"
echo > "$SQL_EXPORT" || exit 9
MY_TABLES=(
"regions"
"instance-types"
"instance-prices"
"block-storage"
)
for MY_TABLE in "${MY_TABLES[@]}"; do
{
echo "DROP TABLE IF EXISTS \"$MY_TABLE\";"
sqlite3 "$MY_DATABASE" ".dump $MY_TABLE"
} >> "$SQL_EXPORT" || exit 9
done
gzip -fk "$SQL_EXPORT" || exit 9
echo -e "\tCSV"
sqlite3 -header -csv "$MY_DATABASE" < "./select/picker.sql" > "$CSV_EXPORT" || exit 9
echo "DONE"