modifiche x fix

This commit is contained in:
2021-04-18 00:50:54 +02:00
parent f41700e946
commit f462bc4ce0

View File

@@ -1,13 +1,48 @@
#!/bin/bash #!/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%'") 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 if [[ $companyID == '' ]]; then
mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE sites --where="company_id = ${companyID}" > sites_${companyID}.sql echo "Company not found!"
sites=$(cut -d',' -f1 sites_${companyID}.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') exit 1
mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE units --where="site_id in ( ${sites} )" > units_${companyID}.sql fi
units=$(cut -d',' -f1 units_${companyID}.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/') companyNS=$(echo $(mysql --login-path=asepath ase_lar -BN -e "select name_short from companies where id = $companyID") | tr '[:space:][:punct:]' '_' )
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/') #dump companies
mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers --extended-insert=FALSE nodes --where="tool_id in ( ${tools} )" > nodes_${companyID}.sql mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-triggers companies --where="id = ${companyID}" > ${companyNS}companies.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 #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