我正在以 cron-job 的形式运行备份脚本,它看起来(大致)像这样:
# Generate temporary directory for output
dest_file=backup-$(date +"%Y%m%d-%H%M") # e.g. backup-20200417-0400
abs_dest_file=/backup/${dest_file} # e.g. /backup/backup-20200417-0400
mkdir -p ${abs_dest_file}
# Copy some stuff to the folder
...
# Generate a tarball
# (creates e.g. /backup/backup-20200417-0400.tar.gz)
tar -C $(dirname ${abs_dest_file}) -czvf ${abs_dest_file}.tar.gz ${dest_file}
# Clean up
rm -r ${abs_dest_file} # /backup/backup-20200417-0400 should be gone here !!
# Sync with some remote hosts
/usr/bin/rsync -avz --include "*.tar.gz" --exclude "*" $(dirname ${abs_dest_file})/ user@host1:/backup
/usr/bin/rsync -avz --include "*.tar.gz" --exclude "*" $(dirname ${abs_dest_file})/ user@host2:/backup
它host1
按预期工作:我最终得到一个文件/backup/backup-20200417-0400.tar.gz
。
然而host2
,也有一个空的创建的目录,例如我最终得到
/backup/backup-20200417-0400 # <- empty folder
/backup/backup-20200417-0400.tar.gz
我不明白为什么会发生这种情况,并且我认为这很奇怪,原因有二:
- 文件夹在呼叫前从机器中删除
rsync
- 我明确只在调用时包含 tarball
rsync
编辑:我还应该注意,这仅在脚本由 cron 运行时才会发生。仅从 shell 执行脚本不会导致文件夹为空。编辑 2:令人讨厌的是,如果我仅安排 cronjob 进行调试,则不会发生这种情况 - 它仅在夜间 cron 作业期间出现(但随后它会持续发生)...
rsync
版本:host
,host2
:3.1.3
;host1
:3.1.1
编辑 3:这是 rsync 调用的详细(vvv)日志,有趣的是完全相同的作为工作主机的日志......
+ /usr/bin/rsync -avvvz --include '*.tar.gz' --exclude '*' /backup/ user@host2:/backup
opening connection using: ssh -l user host2 rsync --server -vvvlogDtprze.iLsfxC . /backup (9 args)
sending incremental file list
[sender] make_file(.,*,0)
[sender] pushing local filters for /backup/
[sender] showing file backup-20200419-0400.tar.gz because of pattern *.tar.gz
[sender] make_file(backup-20200419-0400.tar.gz,*,2)
send_file_list done
send_files starting
server_recv(2) starting pid=26231
recv_file_name(.)
recv_file_name(backup-20200419-0400.tar.gz)
received 16 names
recv_file_list done
get_local_name count=16 /backup
generator starting pid=26231
delta-transmission enabled
recv_generator(.,0)
set modtime of . to (1587261606) Sun Apr 19 04:00:06 2020
recv_generator(.,1)
recv_generator(backup-20200419-0400.tar.gz,16)
recv_files(16) starting
generate_files phase=1
send_files(0, /backup/.)
./
send_files(16, /backup/backup-20200419-0400.tar.gz)
send_files mapped /backup/backup-20200419-0400.tar.gz of size 91256
calling match_sums /backup/backup-20200419-0400.tar.gz
backup-20200419-0400.tar.gz
sending file_sum
false_alarms=0 hash_hits=0 matches=0
sender finished /backup/backup-20200419-0400.tar.gz
recv_files(.)
recv_files(backup-20200419-0400.tar.gz)
got file_sum
set modtime of .backup-20200419-0400.tar.gz.N8E3hW to (1587261606) Sun Apr 19 04:00:06 2020
renaming .backup-20200419-0400.tar.gz.N8E3hW to backup-20200419-0400.tar.gz
set modtime of . to (1587261606) Sun Apr 19 04:00:06 2020
send_files phase=1
recv_files phase=1
generate_files phase=2
send_files phase=2
send files finished
total: matches=0 hash_hits=0 false_alarms=0 data=91256
recv_files phase=2
recv_files finished
generate_files phase=3
generate_files finished
sent 91,346 bytes received 3,723 bytes 190,138.00 bytes/sec
total size is 1,318,611 speedup is 13.87
[sender] _exit_cleanup(code=0, file=main.c, line=1207): about to call exit(0)
答案1
我在另一台主机上运行了一个 cronjob,负责处理空文件夹。愚蠢的错误。