def deleted_old_backups_from_ftp_servers(backups): ftpServersCleaned = [] for vmName in backups: connectionInfo = _get_connectionInfo_by_vmName(vmName) if connectionInfo[0] not in ftpServersCleaned: logging.warn("* a connection to ftp server [{0}] will be performed to see if contains old backups. "\ "If old backups are found, they will be deleted".format(connectionInfo[0])) ftpServersCleaned.append(connectionInfo[0]) ftphost = _get_ftpHost_by_vmName(vmName) ftphost.connect_to_host() backupsOnRemoteFtpServer = backupManager.getBackupsFromFtpServer(ftphost) logging.debug("** Ftp Server [{0}] stores the following backups: \n{1}".format(connectionInfo[0], backupRender.get_backups_infos(backupsOnRemoteFtpServer))) backupsToDelete, backupsToUpload = backupManager.get_backups_for_upload_and_delete(backups, ftphost) if len(backupsToDelete) > 0: logging.warn( "** Ftp Server [{0}] contains {1} old backups that will be now deleted.".format(connectionInfo[0], len(backupsToDelete))) logging.debug("** this are the backups that will be deleted:\n{0}".format( backupRender.get_backups_infos(backupsToDelete))) if _use_real_ftp_sync: backupManager.delete_backups_from_ftpHost(backupsToDelete, ftphost) else: logging.info( "Ftp Server [{0}] does not contains old backups. No file deletions will be performed.".format( connectionInfo[0])) ftphost.disconnect_from_host()
def get_backups_from_ftp_servers(): ''' rebuilds a new dump file by scanning all ftp server's defined in the configuration config.py file. Args: dumpFilePath: str -> the path of the dumpfile ''' result = {} ftpConnections = get_all_ftp_connections() for server in ftpConnections: ftpWrapper = ftpHostFactory.create_ftpHost(server, port=ftpConnections[server][0], user=ftpConnections[server][1], password=ftpConnections[server][2],remoteFolder=ftpConnections[server][3]) try: ftpWrapper.connect_to_host() backupsInFtpHost = backupManager.getBackupsFromFtpServer(ftpWrapper) ftpWrapper.disconnect_from_host() backupManager.merge_first_backup_into_second_backup(backupsInFtpHost, result) except Exception, ex : logging.error("an error occurred in trying to get read backups from host {0}. Please make sure the ftp " "connection to the host is correct!. the error is: {1}. Quitting..".format(ftpWrapper.hostname, str(ex))) sys.exit()
def testConnection(self): backups = backupManager.getBackupsFromFtpServer("localhost", port=2001) self.assertTrue(backups != None)