-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.sh
executable file
·54 lines (41 loc) · 1.32 KB
/
get_data.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
## e.g. ./test.sh device_sensors_par_2015_06 device_0 tracker_motion
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
BLUE_BG='\033[0;44m'
NO_BG='\033[0;49m'
args=$# # Number of args passed.
if [ $args -ne 3 ]
then
echo "Migrate data from Postgres to S3"
echo "Usage: ./get_data [DB-tablename] [datafile-prefix]"
echo "skip_db = yes/no"
echo "offset should integers like 1, 2, etc..."
echo "Example ./test.sh device_sensors_par_2015_06 device_0 tracker_motion 0 no"
echo
exit
fi
# Set arguments
tablename=$1
prefix=$2 # e.g. tracker_motion_master or device_sensors_par_2015_06_?
folder=$3
# compute DB limit and offsets
datafile="${prefix}.csv"
echo "table: $tablename, datafile: $datafile, offset: $offset"
echo
# get data from DB
dbname="sensors1"
username="sensors"
# hostname="sensros-1-replica-2.cdawj8qazvva.us-east-1.rds.amazonaws.com"
hostname="sensors-2-replica-1.cdawj8qazvva.us-east-1.rds.amazonaws.com"
copy_whole_table="\COPY ${tablename} TO '${folder}/${datafile}' DELIMITER ',' CSV"
echo "SQL command: ${copy_whole_table}"
echo "-- Get data for $datafile from database $dbname"
printf "${BLUE}"
psql -h $hostname $dbname -U $username << EOF
${copy_whole_table}
EOF
printf "${NC}"
echo `wc -l ${folder}/${datafile} > ${tablename}.count`