Improved db backup script

Fixed the bad header problem and other small improvements