For example, if I have a java process that (once every 2 hours) takes a backup of a large file, like 500mb, and places it into folder A on HDD A, and I want to schedule a cron script to copy the entire folder A to HDD B once per day... what happens if the cron script happens to fire while the java process is in the middle of writing to folder A? Will it wait? Will it just ignore the file that isn't done being written yet?
In general, Unix commands treat files the same, whether they are open and being written to or not. So if a cron job is using
cp to copy a directory, what gets copied depends solely on what is in the directory at the time the
cp command examines the directory. If a file is only partially written at the time
cp visits it, a partially written copy will be produced. If you want to prevent such occurrences, you need to implement a locking scheme amongst cooperating processes to prevent concurrent access to the directory.