Chris's Wiki :: blog/sysadmin/SafelyUpdatingUnixFiles Commentshttps://utcc.utoronto.ca/~cks/space/blog/sysadmin/SafelyUpdatingUnixFiles?atomcommentsDWiki2006-05-13T17:10:47ZRecent comments in Chris's Wiki :: blog/sysadmin/SafelyUpdatingUnixFiles.From 70.53.120.146 on /blog/sysadmin/SafelyUpdatingUnixFilestag:CSpace:blog/sysadmin/SafelyUpdatingUnixFiles:626e5d1d5ddd6828eddd52faf2d2e9fdddf0e16dFrom 70.53.120.146<div class="wikitext"><p>Not only these steps are important in the event of a system crash, but also if the files being updated are in use by any program. The "ln + mv" steps guarantee that the old file is not overwritten (unlike "cp").</p>
<p>Many Unix admins have probably learned the "ln + mv" steps the hard way, like when trying to manually update libc.so or other critical system files while the system is running, and happily trying "cp libc.so.new /usr/lib/libc.so". Either the cp fails (/bin/cp needs libc.so) and you end up with an empty libc.so, and/or every other program using libc.so crashes, which is pretty much the whole system.</p>
<p>Not too long ago I fell for this while making minor changes to /etc/procmailrc and noticing weird errors in e-mails that were arriving at the exact moment I saved the file (fortunately without loss). Then I wrote a script like what you describe to call "vi" on a procmailrc.temp file then safely replace the original.</p>
<p>Oscar@MIE</p>
</div>2006-05-13T17:10:47ZBy DanielMartin on /blog/sysadmin/SafelyUpdatingUnixFilestag:CSpace:blog/sysadmin/SafelyUpdatingUnixFiles:30f5445013baf5f05b6c4183c65e176307b3be65DanielMartin<div class="wikitext"><p>The chown and chmod commands on most linux variants accept a --reference option that will copy the owner/permission from another file.</p>
<p>I'd be very surprised if you can find an implementation of cp such that cp will exit successfully but cmp will fail without there being a sync in between. (In other words, I see the point of the cmp, but don't see any point in using cmp without a sync)</p>
</div>2006-05-13T13:08:51Z