To connect a main supply with a load and backup battery, the simplest link is to use the diode-OR connection. However, it will not work when the battery voltage is greater than main supply voltage. The circuit below is used to overcome that problem.
Automatic Battery Backup Schematic Wiring Diagram
Component list :
Main switch-mode supply voltage ranges from 7V to 30V.
Max 931 as an ultra-low-power comparator with 1.182V bandgap difference.
R6,C1,D1 will eliminate the supply-rail glitch that would otherwise happen when switching from the battery to the main supply.
For proper operation, the value of R3 and R4 should set the hysteresis in the MAX931 to 800mV.
Source : maxim-ic.com