There is a problem - need to store the database backup on the FTP. On the FTP should not be more than 10 back-ups, ie, After you add backup to FTP should be removed, the old
Here's a shorter solution using lftp
, that'll also work with subdirectories:
#!/bin/bash
# get a list of files and dates from ftp and remove files older than ndays
ftpsite="ftpback-xxx.ovh.net"
ftpuser="user"
ftppass="pass"
#remote folder in which you want to delete files
putdir="/"
nullfolder="/tmp/null"
ndays=19
mkdir -p nullfolder
MM=`date --date="$ndays days ago" +%b`
DD=`date --date="$ndays days ago" +%d`
echo removing files older than $MM $DD
#The no-ssl is there because it's on a local network and remote doesn't support ftp
lftp -e "set ftp:ssl-allow no; mirror $putdir $nullfolder --older-than=now-${ndays}days --Remove-source-files; exit" -u $ftpuser,$ftppass $ftpsite
rm $nullfolder/* -Rf
It has two drawbacks though: