Why not use a hardlink?
rename("myfile", "backup_file")
openat(AT_FDCWD, "myfile", O_WRONLY|O_CREAT, 0644)
unlink("backup_file")
I.e. unlink the old file and create a new one by the same name (with a backup step in between). So the other hard link would keep pointing to the old version of the file.Try it yourself:
echo "test1" > test1
ln test1 test2
vim -c 's/1/2/' -c x test2
cat test1
Edit: Oh, you can configure Vim to break hardlinks $ echo 1 > test1
$ inotifywait --quiet --monitor test1 &
[1] 14321
$ vim -c 's/1/2/' -c x test1
$ cat test1
2
$ <no output from inotifywait>
With multiple hard links, the inode is preserved (only difference is adding the call to ln): $ echo 1 > test1
$ ln test1 test2
$ inotifywait --quiet --monitor test1 &
[1] 14361
$ vim -c 's/1/2/' -c x test1
$ cat test1
2
test1 OPEN
test1 ACCESS
test1 CLOSE_NOWRITE,CLOSE
$