We recently hit a situation in our production ubuntu server that one of our important files were corrupted.
After investigation we found one of my python scripts who write content to that file wrote only part of the content as the node hit disk full scenario exactly at that time.
Can anybody suggest what is the best way to ensure the content is whether fully written or no content is written, so that the file will not land in corrupted state?
That part of my python script is as simple as
with open('workfile', 'w') as f:
f.write("Write some thing")
I did some research, but couldn't get any good pythonic way to do.
And as my file is a growing file, I can't create a temporary file and rename as suggested in atomic writing to file with Python. I will loose old data. And it may make the operation atomic, but what I want is data fully written and not partly.
Even in writing to temporary file and rename, we are not sure that data is completely written to the temporary file.