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() { ...@@ -49,7 +49,7 @@ fail() {
} }
execftp() { execftp() {
lftp -u $FTPUSER,$FTPPASS $FTPTYPE://$FTPHOST -e "$1" lftp -u $FTPUSER,$FTPPASS $FTPTYPE://$FTPHOST -e "$1" 2> /dev/null
[ $? -ge 1 ] \ [ $? -ge 1 ] \
&& fail "Error: ftp command failed: $1" && fail "Error: ftp command failed: $1"
} }
...@@ -113,24 +113,25 @@ if [ "$FTPTYPE" != "ftp" ] && [ "$FTPTYPE" != "sftp" ]; then ...@@ -113,24 +113,25 @@ if [ "$FTPTYPE" != "ftp" ] && [ "$FTPTYPE" != "sftp" ]; then
echo "NO FTP UPLOAD CONFIGURED" echo "NO FTP UPLOAD CONFIGURED"
else else
### FTP: directory permission check ### FTP: directory permission check
ftppwd=$(execftp "mkdir -p $FTPDIR/$date; cd $FTPDIR/$date; pwd; exit") ftpmkdir=$(execftp "mkdir -p $FTPDIR/$date; exit")
FTPDIRnoslash=${FTPDIR%\/} # remove trailing / if [[ "$ftpmkdir" != *"mkdir OK"* ]]; then
if [[ "$ftppwd" != *"$FTPDIRnoslash/$date" ]]; then
fail "Error: failed to create $FTPDIRnoslash/$date on ftp" fail "Error: failed to create $FTPDIRnoslash/$date on ftp"
fi fi
### FTP: delete old backups ### FTP: delete old backups
ftpfiles=$(execftp "cd $FTPDIR; nlist; exit") ftpfiles=$(execftp "cd $FTPDIR; nlist; exit")
# filter files starting with a dot # 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 # find old backups
ftpfilesdelete=() ftpfilesdelete=()
while [ ${#ftpfiles[@]} -ge $FTPNUMBACKUPS]; do while [ ${#ftpfiles[@]} -ge $FTPNUMBACKUPS ]; do
ftpfilesdelete+=(${ftpfiles[0]}) ftpfilesdelete+=(${ftpfiles[0]})
unset ftpfiles[0] ftpfiles=("${ftpfiles[@]:1}")
done done
# delete on ftp # 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 ### FTP: upload
echo "### Upload to FTP..." 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