Is rename() without fsync() safe?

No. Look at libeatmydata, and this presentation: Eat My Data: How Everybody Gets File IO Wrong http://www.oscon.com/oscon2008/public/schedule/detail/3172 by Stewart Smith from MySql. In case it is offline/no longer available, I keep a copy of it: The video here The presentation slides (online version of slides)

What exactly is file.flush() doing?

There’s typically two levels of buffering involved: Internal buffers Operating system buffers The internal buffers are buffers created by the runtime/library/language that you’re programming against and is meant to speed things up by avoiding system calls for every write. Instead, when you write to a file object, you write into its buffer, and whenever the … Read more