How do I convert tiles generated by gdal2tiles.py into an .osm file to then be used in osm2pgsql?

Hello and thanks in advance for any pointers/ideas you can give me. On Ubuntu 20.04, using the tutorials found in switch2osm, I have installed a local tileserver. I converted some GEOTiff images into EPSG:3857 formatted tiles using gdal2tiles.py and would like to have the tileserver serve them in addition to the OSM background files the tileserver is serving up. Can someone suggest a clear and simple path to do this? Again, I have local tiles that leaflet can display (i.e. already in slippy map format) that I want to put into an osm file in order to put into the PostgresSQL DB and be served by my local tileserver. Thanks again in advance for any help/suggestions you can give me.

Regards,
Bill

There’s a lot to unpack here, so let me try to do that. I’ll be doing a lot of speculation, so please let me know if I got something wrong.

On Ubuntu 20.04, using the tutorials found in switch2osm, I have installed a local tileserver

Great, so you have Z/X/Y tiles either as individual files or as 8x8 (or any other size) metatiles
.

I converted some GEOTiff images into EPSG:3857 formatted tiles using gdal2tiles.py

I don’t know the tool, so:

This utility generates a directory with small tiles and metadata, following the OSGeo Tile Map Service Specification. Simple web pages with viewers based on Google Maps, OpenLayers and Leaflet are generated as well - so anybody can comfortably explore your maps on-line and you do not need to install or configure any special software (like MapServer) and the map displays very fast in the web browser. You only need to upload the generated directory onto a web server.

I guess you went for that second way t convert, so you also have Z/X/Y tiles?

would like to have the tileserver serve them in addition to the OSM background files the tileserver is serving up

by tileserver do you mean renderd? if so, you have to recombine your Z/X/Y tiles into renderd metatiles. I once wrote such a tool:

Not sure how well it works today.

I have local tiles […] that I want to put into an osm file in order to put into the PostgresSQL DB and be served by my local tileserver

This one is the hardest to unpack. You already have the tiles, why put them back into PG? What exactly do you mean with ‘osm file’? A .pbf, a .osm? If you have raster files, getting the data out f them is close to impossible because now they’re pixels.