anonprophet
anonprophet

Reputation: 97

Bash script to delete files from remote FTP older than 7 days

i got a bash script from internet, its look good. its already backup, upload FTP, delete old backups older than 7 days.

but its not delete old backup older than 7 days in remote FTP

#!/bin/sh
Mdate="$(date +"%d-%m-%Y")"
mysqldump -uroot -pPassword asia stats | gzip > /home/backup/asia_$Mdate.$

cd /home/backup/

ftpserver="ftp.drivehq.com"
ftpuser="username"
ftppass="password"

ftp -n -i $ftpserver <<EOF
user $ftpuser $ftppass
cd backupstats
mput asia_$Mdate.gz
quit
EOF

find /home/backup/asia_*.gz -maxdepth 1 -type f -mtime +7 -delete

the example backup name will like "asia_17-08-2014.gz"

Thanks in advance for the help.

Upvotes: 0

Views: 1368

Answers (1)

pgl
pgl

Reputation: 8031

Generally the easiest way to keep files for just 7 days is just to name them .mon, .tue, etc. Then you just overwrite the previous week's file every Monday, Tuesday, etc.

Upvotes: 1

Related Questions