Refactored backup and restore Hosts functions