Here's a small bash code snippet to clean up ftp backups maintained by date. Specifically, if using the SysBK to backup to an external server with just ftp access.
It should be run daily via cron and cleans up folders older than 14 days.
#!/bin/bash
# clean_bak.sh
# Cleans up old backup folders from the remote server.
USR=<user>
PSWD=<password>
HOST=<ftp.domain.tld>< br />BAK_PATH=</path/to/backup s>
LFTP=/usr/bin/lftp
RM_DATE=`/bin/date +%m-%d-%y -d '15 days ago'`
$LFTP << EOF
set ftp:ssl-force true
connect $HOST
user $USR $PSWD
rm -r -f $BAK_PATH/${RM_DATE}
du -h -d 1 $BAK_PATH
quit
EOF
exit 0
The du option will output the space currently being used by the backups.
NOTE: For security reasons, you should use ftps protocol to connect to the remote backup server if possible, and can force it via:
set ftp:ssl-force true
This can also be put in the "~/.lftprc" or "~/.lftp/rc" file.
- sandip's blog
- Login or register to post comments