I currently have a setup where I have an emergency server which on a scheduled basis grabs files from my main webserver using wget. If all goes well I want wget to clobber the old cached file. However, if the request returns 404 or something else goes wrong where data cannot be retrieved (e.g. my main server goes down), I don't want the cached data to get clobbered. I've tried using -N which correctly clobbers the data if a new version is available. However, if there is a 404 it clobbers that data with 0 byte files.
If you can modify your web server's configuration or allowed to have .htaccess, you can setup custom error pages. For example, assuming apache as webserver, make an error page
/var/www/error-pages/404-error.html and add the following to your .htaccess or vhosts section.
Alias /error-pages /var/www/error-pages ErrorDocument 404 /error-pages/404-error.html
Together with the alias directive, you can use the same error pages for multiple vhosts if you have more than one. This alone should help not clobbering, but you can also add
-X error-pages to your
wget parameters to skip all custom error pages in general.