def doCreateBackupConfiguration(self, active_agent_id): def check_user_aborted(value): return value is None prompted_config_data = { 'name': None, 'schedule': { 'frequency': None, 'day-of-week': None, 'start-time': { 'hour': None, 'minute': None, 'am-pm': None, 'timezone': tz.get_timezone( self.api['version'] == 1 ) }, 'hourly-interval': None }, 'retention': None, 'notifications': { 'e-mail-addresses': [], 'success': False, 'failure': True }, 'paths': { 'inclusions': [], 'exclusions': [] } } user_aborted = False prompted_config_data['name'] = prompt_user.doPromptBackupConfigurationName( user_aborted ) user_aborted = check_user_aborted(prompted_config_data['name']) frequency_data = prompt_user.doPromptFrequency( self.api['version'], user_aborted ) user_aborted = check_user_aborted(frequency_data) if not user_aborted: prompted_config_data['schedule']['frequency'] = frequency_data['frequency'] prompted_config_data['schedule']['day-of-week'] = frequency_data['dayOfWeek'] prompted_config_data['schedule']['start-time']['hour'] = frequency_data['StartTime']['hour'] prompted_config_data['schedule']['start-time']['minute'] = frequency_data['StartTime']['minute'] prompted_config_data['schedule']['start-time']['am-pm'] = frequency_data['StartTime']['amOrPm'] prompted_config_data['schedule']['start-time']['timezone'] = frequency_data['StartTime']['timeZone'] prompted_config_data['schedule']['hourly-interval'] = frequency_data['interval'] prompted_config_data['retention'] = prompt_user.doPromptRetention( user_aborted ) notification_data = prompt_user.doPromptNotifications( user_aborted ) user_aborted = check_user_aborted(notification_data) if not user_aborted: prompted_config_data['notifications']['e-mail-addresses'] = notification_data['addresses'] prompted_config_data['notifications']['success'] = notification_data['onSuccess'] prompted_config_data['notifications']['failure'] = notification_data['onFailure'] inclusion_data = prompt_user.doPromptFilesAndFolders( user_aborted, inclusion=True ) user_aborted = check_user_aborted(inclusion_data) if not user_aborted: prompted_config_data['paths']['inclusions'] = inclusion_data exclusion_data = prompt_user.doPromptFilesAndFolders( user_aborted, inclusion=False ) user_aborted = check_user_aborted(exclusion_data) if not user_aborted: prompted_config_data['paths']['exclusions'] = exclusion_data if not user_aborted: if self.api['version'] == 1: self.doCreateV1BackupConfiguration( active_agent_id, prompted_config_data ) elif self.api['version'] == 2: self.doCreateV2BackupConfiguration( active_agent_id, prompted_config_data ) else: print('Unknown Cloud Backup API Version') else: print('User Aborted')
def doCreateV1BackupConfiguration(self, active_agent_id, config_data): DayOfWeekMapping = { 'Sunday': 0, 'Monday': 1, 'Tuesday': 2, 'Wednesday': 3, 'Thursday': 4, 'Friday': 5, 'Saturday': 6 } backup_config = cloudbackup.client.backup.BackupConfiguration() # Convert from 24-hour Format to 12-hour AM/PM Format if config_data['schedule']['start-time']['hour'] == 0: config_data['schedule']['start-time']['hour'] = 12 config_data['schedule']['start-time']['am-pm'] = 'AM' elif config_data['schedule']['start-time']['hour'] == 12: config_data['schedule']['start-time']['am-pm'] = 'PM' elif config_data['schedule']['start-time']['hour'] in range(13, 24): config_data['schedule']['start-time']['hour'] = config_data['schedule']['start-time']['hour'] - 12 config_data['schedule']['start-time']['am-pm'] = 'PM' elif config_data['schedule']['start-time']['hour'] in range(1,12): config_data['schedule']['start-time']['am-pm'] = 'AM' backup_config.ConfigurationName = config_data['name'] backup_config.MachineAgentId = int(active_agent_id) backup_config.Active = True backup_config.VersionRetention = config_data['retention'] backup_config.Frequency = config_data['schedule']['frequency'] backup_config.StartTimeHour = config_data['schedule']['start-time']['hour'] backup_config.StartTimeMinute = config_data['schedule']['start-time']['minute'] backup_config.StartTimeAmPm = config_data['schedule']['start-time']['am-pm'] if not config_data['schedule']['day-of-week'] is None: backup_config.DayOfWeekId = DayOfWeekMapping[ config_data['schedule']['day-of-week'] ] else: backup_config.DayOfWeekId = None if config_data['schedule']['frequency'] == 'HOURLY': backup_config.HourInterval = config_data['schedule']['hourly-interval'] if config_data['schedule']['start-time']['timezone'] is not None: backup_config.TimeZoneId = config_data['schedule']['start-time']['timezone'] else: backup_config.TimeZoneId = tz.get_timezone( self.api['version'] == 1 ) backup_config.NotifyRecipients = config_data['notifications']['e-mail-addresses'][0] backup_config.NotifySuccess = config_data['notifications']['success'] backup_config.NotifyFailure = config_data['notifications']['failure'] for item_name, item_type in config_data['paths']['inclusions']: if item_type == 'file': backup_config.AddFile(item_name, excluded=False) else: backup_config.AddFolder(item_name, excluded=False) for item_name, item_type in config_data['paths']['exclusions']: if item_type == 'file': backup_config.AddFile(item_name, excluded=True) else: backup_config.AddFolder(item_name, excluded=True) if not self.backup_engine.CreateBackupConfiguration( backup_config): print('Failed to create backup configuration. See logs for details')
def doCreateBackupConfiguration(self, active_agent_id): def check_user_aborted(value): return value is None prompted_config_data = { "name": None, "schedule": { "frequency": None, "day-of-week": None, "start-time": { "hour": None, "minute": None, "am-pm": None, "timezone": tz.get_timezone(self.api["version"] == 1), }, "hourly-interval": None, }, "retention": None, "notifications": {"e-mail-addresses": [], "success": False, "failure": True}, "paths": {"inclusions": [], "exclusions": []}, } user_aborted = False prompted_config_data["name"] = prompt_user.doPromptBackupConfigurationName(user_aborted) user_aborted = check_user_aborted(prompted_config_data["name"]) frequency_data = prompt_user.doPromptFrequency(self.api["version"], user_aborted) user_aborted = check_user_aborted(frequency_data) if not user_aborted: prompted_config_data["schedule"]["frequency"] = frequency_data["frequency"] prompted_config_data["schedule"]["day-of-week"] = frequency_data["dayOfWeek"] prompted_config_data["schedule"]["start-time"]["hour"] = frequency_data["StartTime"]["hour"] prompted_config_data["schedule"]["start-time"]["minute"] = frequency_data["StartTime"]["minute"] prompted_config_data["schedule"]["start-time"]["am-pm"] = frequency_data["StartTime"]["amOrPm"] prompted_config_data["schedule"]["start-time"]["timezone"] = frequency_data["StartTime"]["timeZone"] prompted_config_data["schedule"]["hourly-interval"] = frequency_data["interval"] prompted_config_data["retention"] = prompt_user.doPromptRetention(user_aborted) notification_data = prompt_user.doPromptNotifications(user_aborted) user_aborted = check_user_aborted(notification_data) if not user_aborted: prompted_config_data["notifications"]["e-mail-addresses"] = notification_data["addresses"] prompted_config_data["notifications"]["success"] = notification_data["onSuccess"] prompted_config_data["notifications"]["failure"] = notification_data["onFailure"] inclusion_data = prompt_user.doPromptFilesAndFolders(user_aborted, inclusion=True) user_aborted = check_user_aborted(inclusion_data) if not user_aborted: prompted_config_data["paths"]["inclusions"] = inclusion_data exclusion_data = prompt_user.doPromptFilesAndFolders(user_aborted, inclusion=False) user_aborted = check_user_aborted(exclusion_data) if not user_aborted: prompted_config_data["paths"]["exclusions"] = exclusion_data if not user_aborted: if self.api["version"] == 1: self.doCreateV1BackupConfiguration(active_agent_id, prompted_config_data) elif self.api["version"] == 2: self.doCreateV2BackupConfiguration(active_agent_id, prompted_config_data) else: print("Unknown Cloud Backup API Version") else: print("User Aborted")
def doCreateV1BackupConfiguration(self, active_agent_id, config_data): DayOfWeekMapping = { "Sunday": 0, "Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5, "Saturday": 6, } backup_config = cloudbackup.client.backup.BackupConfiguration() # Convert from 24-hour Format to 12-hour AM/PM Format if config_data["schedule"]["start-time"]["hour"] == 0: config_data["schedule"]["start-time"]["hour"] = 12 config_data["schedule"]["start-time"]["am-pm"] = "AM" elif config_data["schedule"]["start-time"]["hour"] == 12: config_data["schedule"]["start-time"]["am-pm"] = "PM" elif config_data["schedule"]["start-time"]["hour"] in range(13, 24): config_data["schedule"]["start-time"]["hour"] = config_data["schedule"]["start-time"]["hour"] - 12 config_data["schedule"]["start-time"]["am-pm"] = "PM" elif config_data["schedule"]["start-time"]["hour"] in range(1, 12): config_data["schedule"]["start-time"]["am-pm"] = "AM" backup_config.ConfigurationName = config_data["name"] backup_config.MachineAgentId = int(active_agent_id) backup_config.Active = True backup_config.VersionRetention = config_data["retention"] backup_config.Frequency = config_data["schedule"]["frequency"] backup_config.StartTimeHour = config_data["schedule"]["start-time"]["hour"] backup_config.StartTimeMinute = config_data["schedule"]["start-time"]["minute"] backup_config.StartTimeAmPm = config_data["schedule"]["start-time"]["am-pm"] if not config_data["schedule"]["day-of-week"] is None: backup_config.DayOfWeekId = DayOfWeekMapping[config_data["schedule"]["day-of-week"]] else: backup_config.DayOfWeekId = None if config_data["schedule"]["frequency"] == "HOURLY": backup_config.HourInterval = config_data["schedule"]["hourly-interval"] if config_data["schedule"]["start-time"]["timezone"] is not None: backup_config.TimeZoneId = config_data["schedule"]["start-time"]["timezone"] else: backup_config.TimeZoneId = tz.get_timezone(self.api["version"] == 1) backup_config.NotifyRecipients = config_data["notifications"]["e-mail-addresses"][0] backup_config.NotifySuccess = config_data["notifications"]["success"] backup_config.NotifyFailure = config_data["notifications"]["failure"] for item_name, item_type in config_data["paths"]["inclusions"]: if item_type == "file": backup_config.AddFile(item_name, excluded=False) else: backup_config.AddFolder(item_name, excluded=False) for item_name, item_type in config_data["paths"]["exclusions"]: if item_type == "file": backup_config.AddFile(item_name, excluded=True) else: backup_config.AddFolder(item_name, excluded=True) if not self.backup_engine.CreateBackupConfiguration(backup_config): print("Failed to create backup configuration. See logs for details")