虽然我可以在5分钟后将备份机器上的cron更改为相当闻闻作弊。
解决这个问题的正确方法是什么?
答案 0 :(得分:2)
利用fuser
确定文件是否正在使用中;类似的东西:
#!/bin/sh
MYFILE=myfile #...change as necessary
while true
do
if [ -z "$(/sbin/fuser ${MYFILE} 2> /dev/null)" ]; then
break
fi
echo "...waiting..."
sleep 10 #...adjust as necessary
done
echo "Process the file..."
答案 1 :(得分:1)
假设您可以修改程序的源代码,您可以让“dumper”输出第二个文件,指示它已完成转储。
1. Dumper deletes signal file
2. Dumper dumps file
3. Dumper creates signal file
4. Backup program polls periodically until the signal file is created
5. Backup program deletes signal file
6. Backup program has complete file
不是IPC的最佳形式,而是在另一台机器上......我想你也可以打开一个网络连接进行轮询。
答案 2 :(得分:0)
非常快速而且很脏:
my_file=/my/filename
while [[ -n "$(find $my_file)" -a -n "$(find $my_file -mmin -1)" ]] ; do
echo "File '$my_file' exists, but has been recently modified. Waiting..."
sleep 10
done
scp ... # if the file does not exist at all, we don't wait for it, but let scp fail
答案 3 :(得分:0)
尝试在一个脚本中将文件从主节点复制到备份节点:
1. dumpfile
2. scp
然后保证文件在scp调用之前完成。