def influxdb_restore_points(restore_root, compressed=True): dat = EasyDict() com = RecursiveFormatter(dat, BACKUP_INFO) dat.restore_root = restore_root dat.cont_name = "influxdb" dat.extension = "gz" if compressed else "txt" dat.compressed = "-compressed" if compressed else "" dat.import_influxdb = "{dexec} {cont_name} influx -import -pps {influx_PPS} " + \ " -path={container_file_path} {compressed} " files_list = filter_backup_files(restore_root, print_info=True) if not confirm("Do you want to continue ?"): return run(com.raw_("mkdir -p {influx_bk_target} ")) run(com.raw_("{dexec} {cont_name} mkdir -p {influx_bk_container} ")) for file_ in files_list: local_file_path = pjoin(restore_root, file_) dat.file_name = file_ dat.target_file_path = com.raw_("{influx_bk_target}/{file_name}") dat.container_file_path = "{influx_bk_container}/{file_name}" # if not texists(dat.target_file_path): l_to_t = put(local_file_path, dat.target_file_path) # if l_to_t.failed: # continue t_to_c = run( com.raw_( "docker cp {target_file_path} {cont_name}:{influx_bk_container}/." )) # if t_to_c.failed: # continue # TODO if there are failed points , retry the precedure try_again = run(com.import_influxdb).failed if try_again: dat.influx_PPS = "3000" run(com.import_influxdb) dat.influx_PPS = "7000" print() print(com.raw_(dat.import_influxdb)) print()
def influxdb_export_points(database, backup_root, compress=True): dat = EasyDict() com = RecursiveFormatter(dat, BACKUP_INFO) dat.database = database dat.cont_name = "influxdb" dat.extension = "gz" if compress == True else "txt" dat.compress = "-compress" if compress == True else "" dat.root_data = "/data" with quiet(): if run(com.raw_( "{dexec} {cont_name} test -d {root_data}/data")).failed: dat.root_data = "/var/lib/influxdb" if run(com.raw_( "{dexec} {cont_name} test -d {root_data}/data")).failed: print( red("Did not find root folder for influxdb ./data and ./wal")) return # TODO Maybe something to improve dat.export_influx = "{dexec} {cont_name} influx_inspect export " + \ " -database {database} -datadir {root_data}/data -waldir {root_data}/wal {compress} " + \ " -start {start_date_iso} -end {end_date_iso} -out {influx_bk_container}/{influx_export_file} " strategy = "last_two" if odb.arg.last_two else "full_range" sections_info = influx_section_database_time(database, strategy) # for seq_ in sections_info: # print() # print( seq_.start) # print( seq_.end) # return run(com.raw_("mkdir -p {influx_bk_target}")) run(com.raw_("{dexec} {cont_name} mkdir -p {influx_bk_container} ")) # show("stdout") for seq_ in sections_info: dat.start_date_iso = seq_.start.isoformat() + "Z" dat.end_date_iso = seq_.end.isoformat() + "Z" dat.backup_status = seq_.status if "status" in seq_ else "full" dat.file_month = seq_.start.month dat.file_year = seq_.start.year influxdb_handle_exported(com, backup_root)