Skip to content

Commit

Permalink
RedHat: Extend website idle option to exclude database backup.
Browse files Browse the repository at this point in the history
  • Loading branch information
seth-reeser committed Sep 10, 2023
1 parent 4444c88 commit 58f1eb1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 7 additions & 4 deletions provisioners/redhat/modules/mysql_database_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion provisioners/redhat/modules/mysql_database_table_retain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58f1eb1

Please sign in to comment.