-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexport.sh
More file actions
executable file
·30 lines (27 loc) · 691 Bytes
/
export.sh
File metadata and controls
executable file
·30 lines (27 loc) · 691 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
#!/usr/bin/env bash
MY_DATABASE="ec2.db"
CSV_EXPORT="aws-instances-locations.csv"
SQL_EXPORT="aws-instances-locations.sql"
echo "Export"
echo -e "\tSQL"
echo > "$SQL_EXPORT" || exit 9
MY_TABLES=(
"instance-disks"
"instance-gpus"
"instance-host-prices"
"instance-network-cards"
"instance-shared-prices"
"instance-types"
"locations"
"storage-prices"
"storage-types"
)
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/all-instances-regions.sql" > "$CSV_EXPORT" || exit 9