The Solar Cycle (periods where sunspots decrease and increase) has a big effect on climate. Look up the Maunder Minimum and the Little Ice Age.
https://en.m.wikipedia.org/wiki/Maunder_Minimum
The sunspot level is an indirect measure of the strength of the solar magnetic field, which helps shield the Earth from cosmic ray particles.
Cosmic Ray’s hitting the atmosphere create ions and promote cloud formation. More clouds, less sunlight hitting the ground.
The Sun orbits the galaxy, and in parts of the orbit peeks out of the galactic magnetic field.
https://phys.org/news/2019-11-galaxy-magnetic-field.html
Solar minimum and maximum have probably existed randomly for 4 billion years. They would not account for periodic ice ages of the past 4M years.