Copy whole public repo to a hosted repository

I am trying to configure an apt/yum repository which is the exact mirror of the online public repo available.

I need to know how can I download all the packages from a public repo to a hosted repo and use that repo as offline repo. I need to retain old packages in the repo and do not want the packages to be updated by using the proxy repo.

Is there an easy way to configure such a repo that configures and downloads the packages once and keep them forever?

Proxy repositories don’t have full mirroring functionality, so the standard approach for this situation is to write a script that iterates through the repository’s metadata and fetches each package.

What problem are you trying to solve? Do you need to get ready for a period of being disconnected from the internet? Or are you trying to insulate yourself from upstream changes once you’ve consumed a package, for some reason? Can you give us some more context?

We have old packages requirement for our application which we would like to hold for a long time in the repo, as you mentioned we want to isolate from upstream changes.