You can buy a "thing" that goes in the cigar lighter at the autoparts store that does just this! It's just a little 12v battery methinks.
I have one of those called a "computer saver". It takes a 9V smoke detector battery.
They're available at most FLAPS and work as advertized.
Take it out as soon as the new battery is connected because the 12 volts will "push back" - I don't know if its protected from that.