通过另一个进程的并行处理将文件复制或移动到目录中 [英] Copy or move file into directory with parallel processing from another process
问题描述
我正在AIX上运行两个进程.流程一生成多个文件,流程二从备份目录中的所有文件进行备份.
I'm running two processes on AIX. Process one is generating several files, process two does backups from all files that are in a backup directory.
进程一将文件复制或移动到备份目录中.由于进程2始终在后台运行,因此存在启动备份文件的风险,该文件仍在复制或移动过程中,因此不完整.我该如何避免这个问题?
Process one will copy or move the files into the backup directory. Since process two is always running in the background there is the risk of it starting a backup of a file that is still in the process of being copied or moved and therefore incomplete. How can I avoid this problem?
推荐答案
进程一个应该在另一个目录(在同一磁盘上)中创建文件;创建文件后,将其移至最终目录.Move是一个原子操作,因此process2将只查找完整的文件.
Process one should create files in another directory (on the same disk); and when a file is created, move it into the final directory. Move is an atomic operation, so process2 will only find complete files.
在AIX上,/usr/bin/istat可帮助确保两个目录(或文件)位于同一磁盘/分区/设备上,例如
on AIX, /usr/bin/istat helps to make sure that two directories (or files) are on the same disk/partition/device, e.g.
for Dir in /home /home/zsiga /tmp;
do /usr/bin/istat "$Dir" | grep device;
done
结果:
Inode 2 on device 10/8 Directory
Inode 33 on device 10/8 Directory
Inode 2 on device 10/7 Directory
前两个位于同一磁盘/分区/设备(10/8)上;最后一个在另一台设备(10/7)
The first two are on the same disk/partition/device (10/8); the last one is on another device (10/7)
这篇关于通过另一个进程的并行处理将文件复制或移动到目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!