101 lines
5.5 KiB
Bash
101 lines
5.5 KiB
Bash
#!/bin/bash
|
|
|
|
if [[ $1 == '' ]]; then
|
|
echo "Usage: $0 COMPANY"
|
|
echo " COMPANY: part or full company name"
|
|
echo "This script must be execute from asega user."
|
|
echo "This script create all the DB dumps of configurations tables for a specific company"
|
|
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/')
|
|
if [[ $sites == '' ]]; then
|
|
echo "No sites found!"
|
|
exit 1
|
|
fi
|
|
|
|
#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/')
|
|
if [[ $units == '' ]]; then
|
|
echo "No units found!"
|
|
rm ${companyNS}units.sql
|
|
else
|
|
#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/')
|
|
if [[ $tools == '' ]]; then
|
|
echo "No tools found!"
|
|
rm ${companyNS}tools.sql
|
|
else
|
|
#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
|
|
nodes=$(cut -d',' -f1 ${companyNS}nodes.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/')
|
|
if [[ $nodes == '' ]]; then
|
|
echo "No nodes found!"
|
|
rm ${companyNS}nodes.sql
|
|
else
|
|
#dump calibrations
|
|
nodesC=$(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 ( ${nodesC} )" >${companyNS}calibrations.sql
|
|
calibrations=$(cut -d',' -f1 ${companyNS}calibrations.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/')
|
|
if [[ $calibrations == '' ]]; then
|
|
echo "Warning: No calibrations found for nodes id $nodes!"
|
|
rm ${companyNS}calibrations.sql
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
#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/')
|
|
if [[ $installations == '' ]]; then
|
|
echo "No installations found!"
|
|
rm ${companyNS}installations.sql
|
|
else
|
|
#dump sections
|
|
mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE sections --where="installation_id in ( ${installations} )" >${companyNS}sections.sql
|
|
sections=$(cut -d',' -f1 ${companyNS}sections.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/')
|
|
if [[ $sections == '' ]]; then
|
|
echo "No sections found!"
|
|
rm ${companyNS}sections.sql
|
|
else
|
|
#dump heatmaps
|
|
mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE heatmaps --where="section_id in ( ${sections} )" >${companyNS}heatmaps.sql
|
|
heatmaps=$(cut -d',' -f1 ${companyNS}heatmaps.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/')
|
|
if [[ $heatmaps == '' ]]; then
|
|
echo "No heatmaps found!"
|
|
rm ${companyNS}heatmaps.sql
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
#dump barriers
|
|
mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE barriers --where="unit_id in ( ${units} )" >${companyNS}barriers.sql
|
|
barriers=$(cut -d',' -f1 ${companyNS}barriers.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/')
|
|
if [[ $barriers == '' ]]; then
|
|
echo "No barriers found!"
|
|
rm ${companyNS}barriers.sql
|
|
fi
|
|
fi
|
|
|
|
#dump ctrltools
|
|
mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE ctrltools --where="site_id in ( ${sites} )" >${companyNS}ctrltools.sql
|
|
ctrltools=$(cut -d',' -f1 ${companyNS}ctrltools.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/')
|
|
if [[ $ctrltools == '' ]]; then
|
|
echo "No ctrltools found!"
|
|
rm ${companyNS}ctrltools.sql
|
|
fi
|