Should my script use cp or mv to be more robust?
bash, error-handling, fault, linux, robustness
Solution
I would use a combination:
mv file.dat file.dat.previous
cp file.dat.previous file.dat
That way `file.dat.previous` will always be complete as `mv` is atomic.
Problem
I have a bash script (Scientific Linux). The script has to operate on a file. Let's say "file.dat" (around 1 GB of size) After some time the scripts is restarted and executes the following: ``` if [ -f file.dat ]; then cp file.dat file.previous.dat fi ``` to have a backup of the file. Then a process starts and overwrites "file.dat" In order to be on the safest side (electricity shut down or anything unexpected). What would be the best option: cp or mv ? Thanks.