I am trying to add a way to remove backups older than 3 days ago in my script.
See below a stripped down simplified version, which just leaves the removal part.
It was my understanding that ${BACKUP_DEST[$i]}/$OLDBACKUP
should be outputting something like '/Users/christopherdavies/Desktop/rsync/test1.co.uk/07-06-18'.
However, each time this runs, it deletes the folder above, of 'test1.co.uk', and regardless if it 3 days old or not.
Is anyone able to point me in the right direction? I haven't been able to make any headway... fresh pair of eyes?
#!/bin/sh
WEBSITE_HOST=(
"[email protected]"
"[email protected]"
)
BACKUP_DEST=(
"/Users/christopherdavies/Desktop/rsync/test1.co.uk"
"/Users/christopherdavies/Desktop/rsync/test2.co.uk"
)
OLDBACKUP=`date -d "3 days ago" +"%d%m%Y"`
SITE_COUNT=${#WEBSITE_HOST[@]}
for (( i = 0; i < SITE_COUNT; i++ )); do
# Remove old backups
if [ -d "${BACKUP_DEST[$i]}/$OLDBACKUP" ]; then rm -Rf ${BACKUP_DEST[$i]}/$OLDBACKUP; fi
done
exit 0