added bashup::remove_expired_backups function

This commit is contained in:
Matthew Saunders Brown 2021-04-23 12:52:28 -07:00
parent ab487bdc80
commit 186da55ecb
4 changed files with 52 additions and 78 deletions

View File

@ -65,32 +65,7 @@ if [[ " ${retention_array[@]} " =~ " ${today} " ]]; then
fi
# remove expired backups
for existing_backup in "${existing_backups[@]}"; do
if [[ " ${retention_array[@]} " =~ " ${existing_backup} " ]]; then
# keep $existing_backup, do nothing
one=1;
else
if [[ -d $backup_storage_dir/$existing_backup/files ]]; then
rm -r $backup_storage_dir/$existing_backup/files
fi
if [[ -z "$(ls -A $backup_storage_dir/$existing_backup)" ]]; then
rm -r $backup_storage_dir/$existing_backup
fi
fi
done
bashup::remove_expired_backups files
bashup::unmount_storage_dir
exit 0

View File

@ -43,32 +43,7 @@ if [[ " ${retention_array[@]} " =~ " ${today} " ]]; then
fi
# remove expired backups
for existing_backup in "${existing_backups[@]}"; do
if [[ " ${retention_array[@]} " =~ " ${existing_backup} " ]]; then
# keep $existing_backup, do nothing
one=1;
else
if [[ -d $backup_storage_dir/$existing_backup/mysql ]]; then
rm -r $backup_storage_dir/$existing_backup/mysql
fi
if [ -z "$(ls -A $backup_storage_dir/$existing_backup)" ]; then
rm -r $backup_storage_dir/$existing_backup
fi
fi
done
bashup::remove_expired_backups mysql
bashup::unmount_storage_dir
exit 0

View File

@ -36,32 +36,7 @@ if [[ " ${retention_array[@]} " =~ " ${today} " ]]; then
fi
# remove expired backups
for existing_backup in "${existing_backups[@]}"; do
if [[ " ${retention_array[@]} " =~ " ${existing_backup} " ]]; then
# keep $existing_backup, do nothing
one=1;
else
if [[ -d $backup_storage_dir/$existing_backup/pdns ]]; then
rm -r $backup_storage_dir/$existing_backup/pdns
fi
if [ -z "$(ls -A $backup_storage_dir/$existing_backup)" ]; then
rm -r $backup_storage_dir/$existing_backup
fi
fi
done
bashup::remove_expired_backups pdns
bashup::unmount_storage_dir
exit 0

View File

@ -116,6 +116,55 @@ function bashup::set-retention_array () {
}
function bashup::remove_expired_backups () {
# check for and set directory var
if [ -n "$1" ]; then
directory=$1
else
echo "ERROR: directory var not set"
return 1
fi
# safety check, make sure retention_array is not empty
retention_array_len=${#retention_array[@]}
if [[ $retention_array_len -gt 0 ]]; then
for existing_backup in "${existing_backups[@]}"; do
if [[ " ${retention_array[@]} " =~ " ${existing_backup} " ]]; then
# keep $existing_backup, do nothing
one=1;
else
if [[ -d $backup_storage_dir/$existing_backup/$directory ]]; then
echo rm -r $backup_storage_dir/$existing_backup/$directory
fi
if [[ -z "$(ls -A $backup_storage_dir/$existing_backup)" ]]; then
echo rm -r $backup_storage_dir/$existing_backup
fi
fi
done
else
echo "WARNING: retention array empty or not set."
return 1
fi
}
function bashup::unmount_storage_dir () {
# check if backup_storage_dir is mounted and unmount if so
grep -qs " $backup_storage_dir " /proc/mounts