I'm hoping somebody can look at my crude schematic and tell me what my problem is. It's a battery backup circuit to keep a couple of things with volatile memory alive when the main battery is cut off. It's a 12 volt system in a semi truck and both batteries are lead acid. I've built the system as drawn, and it mostly works. The problem is a minor one but if I cut off the main battery before I turn the ignition switch off, somehow the backup battery keeps the relay on. Once I turn the ignition switch off, everything except what's being backed up goes off as intended and turning the ignition switch back on does nothing. My intent was for the relay to kick off if the main battery was cut off, and from looking at my schematic I can't figure out why it's not working that way.

