#!/bin/bash
filePrefix="dbname"
localDir="/DBBackup"
remoteDir="/Backup"
cd $localDir
oldfile=$filePrefix"_$(date +%Y%m%d)*.sql"
newfile=$filePrefix"_$(date +%Y%m%d)_sql.tar.gz"
tar -czvf $newfile $oldfile
lftp ftp://BackupUser:'username'@192.168.0.1 <<END
cd $remoteDir
lcd $localDir
mput $newfile
bye
END
rm -rf $filePrefix_*.tar.gz
rm -rf $(find $localDir -ctime +2 -name "$filePrefix_*.sql")