def main(): dir = '/backup/mysql/mysql-longterm-backups' pattern = os.path.join(dir, '*/*') cn = 0 for j, i in sorted([(l.split('/')[-1], l) for l in glob.glob(pattern)]): try: a = i.split('/') backup_start_time_str = a[-1].split('-')[0] farm = a[-2] origin_id = 0 backup_start_time = datetime.datetime.strptime(backup_start_time_str, "%Y.%m.%d.%H.%M.%S") backup_size = int(get_directory_size(i)//1024**2) snapshot_dir = i origin_dir = None LongtermInfo.add(farm, origin_id, backup_start_time, backup_size, snapshot_dir, origin_dir) cn += 1 print cn, i, backup_size except Exception as exc: cn += 1 print cn, i print i, exc
def main(args): """entry point""" if args.farm: farm_list = [args.farm] else: farm_list = BackupInfo.get_all_farm() for farm in farm_list: if farm in LONGTERM_BACKUP_IGNORE_FARM: continue backup_obj = BackupInfo.get_oldest_backup_by_farm_role(farm=farm, role='h') if not backup_obj: continue longterm_obj = LongtermInfo.get_latest_by_farm(farm=farm) if longterm_obj: diff = backup_obj.backup_start_time - longterm_obj.backup_start_time if diff.total_seconds() < 3600 * 24 * LONGTERM_BACKUP_MIN_INTERVAL_DAYS: continue dest_file = backup_obj.backup_start_time.strftime('%Y%m%d%H%M%S') dest_file_name = os.path.join(args.dest, farm, dest_file + 'tar.bz2') if os.path.isfile(dest_file_name): continue print backup_obj.backup_dir, '=>', dest_file_name cmd = get_compress_cmd(args.parallel, args.memory, args.block_size, backup_obj.backup_dir, dest_file_name) print ' '.join(cmd) continue p = Popen(cmd, shell=True) p.wait() LongtermInfo.add(farm, backup_obj.id, backup_obj.backup_start_time, backup_obj.backup_size, dest_file_name, backup_obj.backup_dir )