Backup AVR with avrdude
From you script it looks like you are using an STK500 board. You can use the STK500 to do high voltage programming with the attiny chips, so you can always reset the mcu to the factory defaults.

There are certain things you won't be able to fix with your script, for example if you set DWEN or disable the reset functionality, you won't be able to use the ISP interface.