def influx_section_database_time(database, strategy="full"): start_date = start_date_influxdb(database) if start_date is None: print( red("Did not find a valid starting date for database " + database)) return [] time_seq = [] start_date = start_date.replace(day=1, hour=0, minute=0, second=0, microsecond=0) while start_date < datetime.datetime.now(): end_date = (start_date + datetime.timedelta(35)).replace(day=1, hour=0, minute=0, second=0, microsecond=0) tslice = EasyDict() tslice.start = start_date tslice.end = end_date tslice.database = database tslice.status = "full" time_seq.append(tslice) start_date = end_date time_seq[0].status = "start" time_seq[-1].status = "part" if strategy == "last_two": return time_seq[-2:] return time_seq
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)