improvement db export tool

This commit is contained in:
2021-04-18 10:16:02 +02:00
parent f462bc4ce0
commit 049cca0ca4

View File

@@ -19,30 +19,80 @@ mysqldump --login-path=asepath ase_lar --compact --no-create-info --skip-trigger
#dump sites #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 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/') 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 #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 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/') 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 #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 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/') 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 #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 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 #dump calibrations
calibrations=$(cut -d',' -f4 ${companyNS}nodes.sql | tr '\n' ',' | sed 's/,$/\n/') 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 ( ${calibrations} )" > ${companyNS}calibrations.sql 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 #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 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/') installations=$(cut -d',' -f1 ${companyNS}installations.sql | cut -d'(' -f2 | tr '\n' ',' | sed 's/,$/\n/')
#dump sections
if [[ $installations == '' ]]; then if [[ $installations == '' ]]; then
echo "No installations found!" echo "No installations found!"
rm ${companyNS}installations.sql rm ${companyNS}installations.sql
else 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 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 fi