Commit 496d7b1e authored by Fjen Undso's avatar Fjen Undso
Browse files

fix deletion of files on ftp

lftp was too verbose
the ftpfilesdelete array had magically some ' on first and last element
parent d7026652
......@@ -49,7 +49,7 @@ fail() {
}
execftp() {
lftp -u $FTPUSER,$FTPPASS $FTPTYPE://$FTPHOST -e "$1"
lftp -u $FTPUSER,$FTPPASS $FTPTYPE://$FTPHOST -e "$1" 2> /dev/null
[ $? -ge 1 ] \
&& fail "Error: ftp command failed: $1"
}
......@@ -113,24 +113,25 @@ if [ "$FTPTYPE" != "ftp" ] && [ "$FTPTYPE" != "sftp" ]; then
echo "NO FTP UPLOAD CONFIGURED"
else
### FTP: directory permission check
ftppwd=$(execftp "mkdir -p $FTPDIR/$date; cd $FTPDIR/$date; pwd; exit")
FTPDIRnoslash=${FTPDIR%\/} # remove trailing /
if [[ "$ftppwd" != *"$FTPDIRnoslash/$date" ]]; then
ftpmkdir=$(execftp "mkdir -p $FTPDIR/$date; exit")
if [[ "$ftpmkdir" != *"mkdir OK"* ]]; then
fail "Error: failed to create $FTPDIRnoslash/$date on ftp"
fi
### FTP: delete old backups
ftpfiles=$(execftp "cd $FTPDIR; nlist; exit")
# filter files starting with a dot
$ftpfiles=( $(echo $ftpfiles | sed 's,\.[A-Za-z0-9_\/\.]* , ,g') )
ftpfiles=( $(echo $ftpfiles | sed 's,\.[A-Za-z0-9_\/\.]* , ,g') )
# find old backups
ftpfilesdelete=()
while [ ${#ftpfiles[@]} -ge $FTPNUMBACKUPS]; do
while [ ${#ftpfiles[@]} -ge $FTPNUMBACKUPS ]; do
ftpfilesdelete+=(${ftpfiles[0]})
unset ftpfiles[0]
ftpfiles=("${ftpfiles[@]:1}")
done
# delete on ftp
execftp "cd $FTPDIR; rm -r ${ftpfilesdelete[@]}; exit"
[ ${#ftpfilesdelete[@]} -ge 1 ] \
&& ftpfilesdelete=${ftpfilesdelete[@]} \ # lftp has problems with arrays
&& execftp "cd $FTPDIR; rm -r $ftpfilesdelete; exit"
### FTP: upload
echo "### Upload to FTP..."
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment