Merge "Database backup fix"

This commit is contained in:
Zuul 2019-10-23 19:16:28 +00:00 committed by Gerrit Code Review
commit 24c1cd4514
2 changed files with 14 additions and 18 deletions

View File

@ -24,21 +24,19 @@ MYSQL="mysql \
MYSQLDUMP="mysqldump \ MYSQLDUMP="mysqldump \
--defaults-file=/etc/mysql/admin_user.cnf" --defaults-file=/etc/mysql/admin_user.cnf"
days_difference() { seconds_difference() {
archive_date=$( date --date="$1" +%s ) archive_date=$( date --date="$1" +%s )
if [ "$?" -ne 0 ] if [ "$?" -ne 0 ]
then then
day_delta=0 second_delta=0
fi fi
current_date=$( date +%s ) current_date=$( date +%s )
date_delta=$(($current_date-$archive_date)) second_delta=$(($current_date-$archive_date))
if [ "$date_delta" -lt 0 ] if [ "$second_delta" -lt 0 ]
then then
day_delta=0 second_delta=0
else
day_delta=$(($date_delta/86400))
fi fi
echo $day_delta echo $second_delta
} }
DBNAME=( $($MYSQL --silent --skip-column-names -e \ DBNAME=( $($MYSQL --silent --skip-column-names -e \
@ -108,7 +106,7 @@ if [ $ARCHIVE_RET -eq 0 ]
for archive_file in $(ls -1 $ARCHIVE_DIR/*.gz) for archive_file in $(ls -1 $ARCHIVE_DIR/*.gz)
do do
archive_date=$( echo $archive_file | awk -F/ '{print $NF}' | cut -d'.' -f 3) archive_date=$( echo $archive_file | awk -F/ '{print $NF}' | cut -d'.' -f 3)
if [ "$(days_difference $archive_date)" -gt "$MARIADB_BACKUP_DAYS_TO_KEEP" ] if [ "$(seconds_difference $archive_date)" -gt "$(($MARIADB_BACKUP_DAYS_TO_KEEP*86400))" ]
then then
rm -rf $archive_file rm -rf $archive_file
fi fi

View File

@ -36,21 +36,19 @@ delete_files() {
} }
#Get the day delta since the archive file backup #Get the day delta since the archive file backup
days_difference() { seconds_difference() {
archive_date=$( date --date="$1" +%s ) archive_date=$( date --date="$1" +%s )
if [ "$?" -ne 0 ] if [ "$?" -ne 0 ]
then then
day_delta=0 second_delta=0
fi fi
current_date=$( date +%s ) current_date=$( date +%s )
date_delta=$(($current_date-$archive_date)) second_delta=$(($current_date-$archive_date))
if [ "$date_delta" -lt 0 ] if [ "$second_delta" -lt 0 ]
then then
day_delta=0 second_delta=0
else
day_delta=$(($date_delta/86400))
fi fi
echo $day_delta echo $second_delta
} }
#Create backups directory if it does not exists. #Create backups directory if it does not exists.
@ -90,7 +88,7 @@ if [ $ARCHIVE_RET -eq 0 ]
for archive_file in $(ls -1 $ARCHIVE_DIR/*.gz) for archive_file in $(ls -1 $ARCHIVE_DIR/*.gz)
do do
archive_date=$( echo $archive_file | awk -F/ '{print $NF}' | cut -d'.' -f 3) archive_date=$( echo $archive_file | awk -F/ '{print $NF}' | cut -d'.' -f 3)
if [ "$(days_difference $archive_date)" -gt "$POSTGRESQL_BACKUP_DAYS_TO_KEEP" ] if [ "$(seconds_difference $archive_date)" -gt "$(($POSTGRESQL_BACKUP_DAYS_TO_KEEP*86400))" ]
then then
rm -rf $archive_file rm -rf $archive_file
fi fi