  Aims. Lunar soil and rocks are not protected by a magnetic field or an
atmosphere and are continuously irradiated by energetic particles that can
produce cosmogenic radioisotopes directly inside rocks at different depths
depending on the particle's energy. This allows the mean fluxes of solar and
galactic cosmic rays to be assessed on the very long timescales of millions of
years. Methods. Here we show that lunar rocks can serve as a very good particle
integral spectrometer in the energy range 20-80 MeV. We have developed a new
method based on precise modeling, that is applied to measurements of $^{26}$Al
(half-life ~0.7 megayears) in lunar samples from the Apollo mission, and
present the first direct reconstruction (i.e., without any a priori
assumptions) of the mean energy spectrum of solar and galactic energetic
particles over a million of years. Results. We show that the reconstructed
spectrum of solar energetic particles is totally consistent with that over the
last decades, despite the very different levels of solar modulation of galactic
cosmic rays ($\phi=496\pm 40$ MV over a million years versus $\phi= 660\pm 20$
MV for the modern epoch). We also estimated the occurrence probability of
extreme solar events and argue that no events with the F(>30 MeV) fluence
exceeding $5*10^{10}$ and $10^{11}$ cm$^2$ are expected on timescales of a
thousand and million years, respectively. Conclusions. We conclude that the
mean flux of solar energetic particles hardly depends on the level of solar
activity, in contrast to the solar modulation of galactic cosmic rays. This
puts new observational constraints on solar physics and becomes important for
assessing radiation hazards for the planned space missions.
