From 58f1eb1abb65a33aaca16ab3a1ee7d9bad7a6c05 Mon Sep 17 00:00:00 2001 From: Seth Reeser Date: Sun, 10 Sep 2023 11:11:52 -0400 Subject: [PATCH] RedHat: Extend website idle option to exclude database backup. --- VERSION.yml | 2 +- provisioners/redhat/modules/mysql_database_backup.sh | 11 +++++++---- .../redhat/modules/mysql_database_table_retain.sh | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/VERSION.yml b/VERSION.yml index b04e2d85..d6662c51 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,5 +1,5 @@ --- -version: 4.7.1 +version: 4.8.0 major: description: "Catapult uses Semantic Versioning. During a MAJOR increment, incompatable API changes are made which require a manual upgrade path. Please follow these directions:" notice: "NEW MAJOR VERSION OF CATAPULT AVAILABLE" diff --git a/provisioners/redhat/modules/mysql_database_backup.sh b/provisioners/redhat/modules/mysql_database_backup.sh index a79cda81..965a8545 100644 --- a/provisioners/redhat/modules/mysql_database_backup.sh +++ b/provisioners/redhat/modules/mysql_database_backup.sh @@ -4,6 +4,7 @@ branch=$(catapult environments.$1.branch) dbconf="/catapult/provisioners/redhat/installers/temp/${1}.cnf" domain=$(catapult websites.apache.$5.domain) domain_valid_db_name=$(catapult websites.apache.$5.domain | tr "." "_" | tr "-" "_") +idle=$(catapult websites.apache.$5.idle) software=$(catapult websites.apache.$5.software) software_dbprefix=$(catapult websites.apache.$5.software_dbprefix) software_workflow=$(catapult websites.apache.$5.software_workflow) @@ -18,12 +19,16 @@ if ([ ! -z "${software}" ]); then if ([ "${1}" = "production" ] && [ "${software_workflow}" = "downstream" ] && [ "${software_db}" != "" ] && [ "${software_db_tables}" != "0" ]) || ([ "${1}" = "test" ] && [ "${software_workflow}" = "upstream" ] && [ "${software_db}" != "" ] && [ "${software_db_tables}" != "0" ]); then # dump the database as long as it hasn't already been dumped for the day - if ! [ -f /var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d").sql.lock ]; then + if [ "${idle}" = "True" ]; then + echo -e "\t* skipping database backup, website is set to idle" + elif [ -f /var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d").sql.lock ]; then + echo -e "\t* a database backup was already performed today" + else echo -e "\t* performing a database backup" # create the _sql directory if it does not exist mkdir --parents "/var/www/repositories/apache/${domain}/_sql" # dump the database - mysqldump --defaults-extra-file=$dbconf --lock-tables=false --single-transaction --quick ${1}_${domain_valid_db_name} > /var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d").sql + mysqldump --defaults-extra-file=$dbconf --lock-tables=false --max_allowed_packet=512M --single-transaction --quick ${1}_${domain_valid_db_name} > /var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d").sql # write out a sql lock file for use in controlling what is restored in other environments touch "/var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d").sql.lock" # ensure no more than 250mb or at least the one, newest, YYYYMMDD.sql file exists @@ -48,8 +53,6 @@ if ([ ! -z "${software}" ]); then && git add --all "_sql" \ && git commit --message="Catapult auto-commit ${1}:${software_workflow}:software_database" \ && sudo ssh-agent bash -c "ssh-add /catapult/secrets/id_rsa; git fetch && git pull origin ${branch} && git push origin ${branch}" - else - echo -e "\t* a database backup was already performed today" fi fi diff --git a/provisioners/redhat/modules/mysql_database_table_retain.sh b/provisioners/redhat/modules/mysql_database_table_retain.sh index 9d7f0a09..6196eee7 100644 --- a/provisioners/redhat/modules/mysql_database_table_retain.sh +++ b/provisioners/redhat/modules/mysql_database_table_retain.sh @@ -27,7 +27,7 @@ if ([ ! -z "${software}" ]); then mkdir --parents "/var/www/repositories/apache/${domain}/_sql" # dump the database tables that are specified # note if there is an invalid table, there will be an error of: mysqldump: Couldn't find table: "test" - mysqldump --defaults-extra-file=$dbconf --lock-tables=false --single-transaction --quick ${1}_${domain_valid_db_name} ${software_dbtable_retain[*]} > /var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d")_software_dbtable_retain.sql + mysqldump --defaults-extra-file=$dbconf --lock-tables=false --max_allowed_packet=512M --single-transaction --quick ${1}_${domain_valid_db_name} ${software_dbtable_retain[*]} > /var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d")_software_dbtable_retain.sql # write out a sql lock file for use in controlling what is restored in other environments touch "/var/www/repositories/apache/${domain}/_sql/$(date +"%Y%m%d")_software_dbtable_retain.sql.lock" # ensure no more than 50mb or at least the one, newest, YYYYMMDD_software_dbtable_retain.sql file exists