From f462bc4ce0a982d627f392fc75cf04c38b27394f Mon Sep 17 00:00:00 2001 From: Alessandro Battilani Date: Sun, 18 Apr 2021 00:50:54 +0200 Subject: [PATCH] modifiche x fix --- dump_company_config.sh | 55 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/dump_company_config.sh b/dump_company_config.sh index 20485c1..079fdfd 100644 --- a/dump_company_config.sh +++ b/dump_company_config.sh @@ -1,13 +1,48 @@ #!/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%'") -mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers companies --where="id = ${companyID}" > companies_${companyID}.sql -mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE sites --where="company_id = ${companyID}" > sites_${companyID}.sql -sites=$(cut -d',' -f1 sites_${companyID}.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') -mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE units --where="site_id in ( ${sites} )" > units_${companyID}.sql -units=$(cut -d',' -f1 units_${companyID}.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') -mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE tools --where="unit_id in ( ${units} )" > tools_${companyID}.sql -tools=$(cut -d',' -f1 tools_${companyID}.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') -mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE nodes --where="tool_id in ( ${tools} )" > nodes_${companyID}.sql -calibrations=$(cut -d',' -f4 nodes_${companyID}.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} )" > calibrations_${companyID}.sql \ No newline at end of file +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 \ No newline at end of file