Commit 56c900bf authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Finish data warehouse load script

Update load.sh, add test_data.sql and modify net usage related objects.
Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent a7d6d8c4
......@@ -45,6 +45,8 @@ comment on column sa_inventory.kernel is 'Longest kernel version has 24'
'characters';
comment on table sa_net_usage is 'Transition table with temporary network '
'usage data per machine';
comment on column sa_net_usage.insertion_date is 'To avoid using lock during '
'the load';
/* -------------------------------------------------------------------------- */
/* Data Warehouse */
......
......@@ -44,6 +44,7 @@ create table sa_inventory (
/* Transition table with temporary network usage data per machine */
create table sa_net_usage (
insertion_date date not null, /* To avoid using lock during the load */
inep text not null,
machine macaddr not null,
collect_time timestamp not null,
......
......@@ -19,27 +19,26 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
if test $# -lt 1 -o $# -gt 6; then
printf "Usage: ./load.sh <database>\n"
if test $# -ne 2; then
printf "Usage: ./load.sh <database> <dump_file>\n"
exit 1
fi
database=$1
DUMPDIR="/home/postgres/dump"
LOADDIR="/home/postgres/load"
DUMPFILE="${DUMPDIR}/backup_$(date +%F).sql"
PREFIX="$(dirname $(readlink -f $0))"
DUMPPARAM="-Fc -b"
database=$1
dump_file=$2
date +"Backup started at %F %T"
pg_dump ${DUMPPARAM} ${database} > "${DUMPFILE}"
pg_dump ${DUMPPARAM} ${database} > "${dump_file}"
date +"Backup completed at %F %T"
date +"Data warehouse load started at %F %T"
psql -d ${database} -f "${LOADDIR}/load_data_warehouse.sql"
psql -d ${database} -f "${PREFIX}/load_data_warehouse.sql"
psql -d ${database} -c "select load_data_warehouse();"
date +"Data warehouse load finished at %F %T"
date +"Data marts load started at %F %T"
psql -d ${database} -f "${LOADDIR}/load_data_marts.sql"
psql -d ${database} -f "${PREFIX}/load_data_marts.sql"
psql -d ${database} -c "select load_data_marts();"
date +"Data marts load finished at %F %T"
This diff is collapsed.
......@@ -22,14 +22,15 @@
# This script migrates the data from mectb00_net_staging_area to sa_net_usage
if test $# -ne 1; then
printf "Usage: ./create_database.sh <database>\n"
printf "Usage: ./load_sa_net_usage.sh <database>\n"
exit 1
fi
database=$1
psql -d ${database} -c "insert into sa_net_usage (insertion_date, inep,
machine, collect_time, down_bytes, down_packages, up_bytes, up_packages)
select current_date, net_inep, net_mac::macaddr, net_data + net_hora,
psql -d ${database} -c "
insert into sa_net_usage (insertion_date, inep, machine, collect_time,
down_bytes, down_packages, up_bytes, up_packages)
select current_date - 1, net_inep, net_mac::macaddr, net_data + net_hora,
net_bytes_in, net_pacotes_in, net_bytes_out, net_pacotes_out from
mectb00_net_staging_area;"
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment