backup_database.sh: substantial rewrite to operate in more automated manner.