I'm doing backup via a shell script on multiple machines and uploading the files to a FTP server.
The backup is triggered either by Ansible (or for testing purposes via a cronjob). All servers are identical, but the FTP program works on some machines and on some other machines it lies. The lie No such file (or directory)
is only made when started by Ansible or cronjob. When I run the script from my SSH shell then it works perfectly fine as intended.
#!/bin/bash
mkdir /backup/$(date +\%F)
# files to backup are created within the created folder
printf "open 192.168.1.1
user username password
passive
mkdir /`date +%Y-%m-%d`/servername
cd /`date +%Y-%m-%d`/servername
lcd /backup/`date +%Y-%m-%d`
binary
mput *
bye
" > /backup/batch.ftp
ftp -inv < /backup/batch.ftp
rm -r /backup/$(date +\%F)
rm /backup/batch.ftp
So goal is to create on the backup server a folder for each day and within a folder for each server. On some servers the files are actually put into the folder with the server name. On other servers the files are put into the FTP root directory. As mentioned all the servers and backup scripts are identical.
The FTP log of a server that lies:
Connected to 192.168.1.1.
220-FileZilla Server 1.0.1
220 Please visit https://filezilla-project.org/
331 Please, specify the password.
230 Login successful.
Remote system type is UNIX.
Passive mode on.
550 No such file or directory
550 No such file
Local directory now /backup/2023-01-24
200 Type set to I
local: site-hv2.tar.gz remote: site-hv2.tar.gz
227 Entering Passive Mode (172,16,241,11,246,63)
150 Starting data transfer.
226 Operation successful
377565560 bytes sent in 15.18 secs (23.7268 MB/s)
200 Goodbye.
As mentioned when I run the script from my shell then it always works. When it is triggered automatically it lies on some machines always and on some machines never. All machines are Ubuntu Server 20.04.
The mkdir FTP command says "No such file or directory" which is BS, as it should create it. Obviously it's not there. The date folder is created by the first server that runs the backup script which works always, so the command is correct and it indeed creates the two folders recursively. The second "No such file" by the cd command obviously doesn't work as mkdir refused to make the directory.