简体   繁体   中英

bash backup script - pleskbackup + lftp

I would like to ask you for a help. I'm a scripting noob and I need to make a script for backing up our webserver via FTPS. I made this script, but it only makes the backup file, but it does not upload that file to the FTPS server. But when I run that lftp command alone, it works. I'm looking at this for quite a long time, but I can't find out, why it's not working... Could someone help please? Thank you!

#!/bin/bash

# SETTINGS

RMDATE=$(date --iso -d '10 days ago').tar
FTPUSER=user
FTPPW=pass
FTPSERVER=my.server.com
LFTP=/usr/bin/lftp

# DELETE OLD BACKUPS

rmold () {
$LFTP << EOF
open ${FTPUSER}:${FTPPW}@${FTPSERVER}
rm -rf ${RMDATE}
bye
EOF
echo "Done."
}

# PLESK BACKUP

if /usr/local/psa/bin/pleskbackup server -v --exclude-logs >/tmp/backup-plesk.log 2>&1 --output-file=/var/www/bak/`date -I`.tar; then
        if lftp -c "open ${FTPUSER}:${FTPPW}@${FTPSERVER}; put /var/www/bak/`date -I`.tar"; then
                rm -f /var/www/bak/`date -I`.tar
                /usr/bin/sendEmail <<< some parameters >>> # backup success message
                rmold
        else
                /usr/bin/sendEmail <<< some parameters >>> # upload error message
        exit 1
        fi
else
        /usr/bin/sendEmail <<< some parameters >>> # backup error message
        exit 1
fi

I had a problem with FTP FEAT and certificate. I disabled FEAT in lftp config file and I specified full path to the certificate. It works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM