#!/bin/bash if [[ $1 == '' ]]; then echo "Usage: $0 COMPANY" echo " COMPANY: part or full company name" exit 1 fi companyID=$(mysql --login-path=asepath ase_lar -BN -e "select id from companies where name like '%$1%'") if [[ $companyID == '' ]]; then echo "Company not found!" exit 1 fi companyNS=$(echo $(mysql --login-path=asepath ase_lar -BN -e "select name_short from companies where id = $companyID") | tr '[:space:][:punct:]' '_' ) #dump companies mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers companies --where="id = ${companyID}" > ${companyNS}companies.sql #dump sites mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE sites --where="company_id = ${companyID}" > ${companyNS}sites.sql sites=$(cut -d',' -f1 ${companyNS}sites.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') #dump units mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE units --where="site_id in ( ${sites} )" > ${companyNS}units.sql units=$(cut -d',' -f1 ${companyNS}units.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') #dump tools mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE tools --where="unit_id in ( ${units} )" > ${companyNS}tools.sql tools=$(cut -d',' -f1 ${companyNS}tools.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') #dump nodes mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE nodes --where="tool_id in ( ${tools} )" > ${companyNS}nodes.sql #dump calibrations calibrations=$(cut -d',' -f4 ${companyNS}nodes.sql | tr '\n' ',' | sed 's/,$/\n/') mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE calibrations --where="id in ( ${calibrations} )" > ${companyNS}calibrations.sql #dump installations mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE installations --where="site_id in ( ${sites} )" > ${companyNS}installations.sql installations=$(cut -d',' -f1 ${companyNS}installations.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') #dump sections if [[ $installations == '' ]]; then echo "No installations found!" rm ${companyNS}installations.sql else mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE sections --where="installation_id in ( ${installations} )" > ${companyNS}sections.sql fi