简体   繁体   中英

Missed files using mv in bash script

I have a script in bash that moves a lot of files from one hard drive to another. The problem is that sometimes the script generate a lot of files empty in the destination folder and deleted the files in the original folder (I suspect that this happens when the destination disk is full) This is basically the lines of code that I think they cause the problem:

find /mnt/$server/ar/Folder01 -mtime +30 -exec mv -t /home/user/Folder01/$server/ {} \+
find /mnt/$server/ar/Folder02 -mtime +30 -exec mv -t /home/user/Folder02/$server/ {} \+

I can't use mv * because the folder have too many files.

Some idea or suggestion?

From info coreutils mv

mv can move any type of file from one file system to another. Prior to version 4.0 of the fileutils, mv could move only regular files between file systems. For example, now mv can move an entire directory hierarchy including special device files from one partition to another. It first uses some of the same code that's used by cp -a to copy the requested directories and files, then (assuming the copy succeeded) it removes the originals. If the copy fails, then the part that was copied to the destination partition is removed. If you were to copy three directories from one partition to another and the copy of the first directory succeeded, but the second didn't , the first would be left on the destination partition and the second and third would be left on the original partition.

So it seems that it will delete only if the copy is succeeded.
It should be the opposite for file with 0 size: you should have finished the space in the origin filesystem instead. (You create a file with its filename but you cannot give it any sector free to write in).
A sync before you start to copy can help in the case you have not finished the space but the system is waiting to write the file on the disk (It should not be needed but you can always do it... )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM