Battery in parallel with main power source
Paralleling power sources is a Bad Idea™. The simplest solution is to use two diodes to separate them.  

Suppose the main power source is 12 V and the battery 9 V. Then the 12 V source will drop, say, 0.5 V (Schottky diode), so the voltage at the cathode will be 11.5 V, which is higher than the battery's 9 V, so that diode won't conduct current. When the main source is off the battery will supply power via its diode.  

Note that the highest voltage has priority, that's why I chose 12 V and 9 V as example. If the main power supply would be for instance 8 V then the battery would supply the power all the time.