I have 2 web servers. Let's call them local and remote just for simplicity. Local: I've only ftp and cron access, Remote: ssh/ftp
I wrote a simple backup script, which tars the files and then sends them to the remote server. (called in cron) Local server is added in ~/.ssh/authorized_keys on the remote server to make connection without using password.
cd $FILES_TO_BACKUP_DIR
for dir in */
do
base=$(basename "$dir")
tar -czpf "$BACKUP_DIR/${base}-$DATE.tar.gz" "$dir"
rsync -az -e "ssh -p $REMOTE_HOST_PORT -i $KEY_PATH" $BACKUP_DIR $REMOTE_HOST_ADDRESS:$REMOTE_BACKUP_DIR
rm $BACKUP_DIR/${base}-$DATE.tar.gz
done
I think it works fine - the files are appearing on the remote server. I've compared sizes of all files and checksums of some of them. Everything matches.
However I'm not sure about this message:
Connection to xxx.xxx.xxx.xxx closed by remote host.
It appears different number of times each time the script is called.
For the testing purposes, I copy around 20 tars.
I've added set -x
at the beginning of the script to show each line as it's executing.
Here is part of the log:
./backup.sh
+ cd /home/tobackup/
+ for dir in '*/'
++ basename lgsm/
+ base=lgsm
+ tar -czpf /home/test/_backups/backups-tmp/lgsm-09-01-2020.tar.gz lgsm/
+ rsync -vaz -e 'ssh -p PORT' /home/test/_backups/backups-tmp USER@IP:/home/backups_test/_backups/backups
sending incremental file list
backups-tmp/
backups-tmp/lgsm-09-01-2020.tar.gz
backups-tmp/serverfiles-09-01-2020.tar.gz
Connection to IP closed by remote host.
sent 237,480,856 bytes received 10,786 bytes 6,168,614.08 bytes/sec
total size is 241,069,740 speedup is 1.02
+ rm /home/test/_backups/backups-tmp/lgsm-09-01-2020.tar.gz
+ for dir in '*/'
++ basename log/
+ base=log
+ tar -czpf /home/test/_backups/backups-tmp/log-09-01-2020.tar.gz log/
+ rsync -vaz -e 'ssh -p PORT' /home/test/_backups/backups-tmp USER@IP:/home/backups_test/_backups/backups
sending incremental file list
backups-tmp/
backups-tmp/log-09-01-2020.tar.gz
Connection to IP closed by remote host.
sent 900 bytes received 81 bytes 654.00 bytes/sec
total size is 237,899,887 speedup is 242,507.53
+ rm /home/test/_backups/backups-tmp/log-09-01-2020.tar.gz
+ for dir in '*/'
++ basename serverfiles/
+ base=serverfiles
+ tar -czpf /home/test/_backups/backups-tmp/serverfiles-09-01-2020.tar.gz serverfiles/
I'm curious why this is happening and if it's possible, how can I prevent such behavior. (If it's not important as it seems I'd like to hide the message, but keep potential other error messages. I've tried using rsync -q
to suppress the message,)