#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace

printf "\n## Start deleting out-of-date backup file ... \n"
printf "\n## Current date is %s \n" "$(date)"

outofdate=`date +%Y%m%d --date="-15 day"`
rootpath="/data/fullbackup/"
oodbackup=$rootpath$outofdate$".tgz"

if [ ! -f "$oodbackup" ]; then
        printf "\n## no out-of-date backup file "$oodbackup" found, nothing has been deleted ... \n"
    else
	rm -f "${oodbackup}"
        printf "\n## the latest out-of-date backup file "$oodbackup" has been deleted ... \n"
      exit
fi
