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 delete_failed_backups(candidateFailedUploads): ''' Deletes backups that have not been uploaded correctly ''' import pdb pdb.set_trace() logging.warn('this are the backus that failed :') for vmName in candidateFailedUploads: logging.warn('- ' + vmName) logging.warn('the cleanup of invalid backups will now start') if _use_real_ftp_sync: for vmName in candidateFailedUploads: ftphost = _get_ftpHost_by_vmName(vmName) backupManager.delete_backups_from_ftpHost(candidateFailedUploads, ftphost) logging.info('backup files for {0} have been deleted.')