What benefit does Russia get from keeping Assad in power? What is the history behind the relationship between Russia and the Syrian government?
There are multiple reasons for that:
[Geopolitical/Military] Naval base in Tartus
As @dan-klasson's answer noted, it is the only naval base left to Russia outside of its own territory; and its only forward base.
[Geopolitical/Legal] Opposition to separatism and interventionism
Russia is not a homogeneous country (even less so if you include its near abroad imperial ambitions).
As such, it is highly vulnerable to separatism (and interventionism in support of separatism).
Therefore, they strongly oppose any international precedent that can normalize the idea of supporting separatism.
This was one of the 3 major reasons for their support of Serbia against Kosovo albanians; it's also the reason they oppose Syrian territorial integrity challenges; both internal by rebels and external by the West.
Obviously hypocritical considering their own behavior in Georgia/Baltics/Ukraine, but there ain't no law against hypocricy.
[Geopolitical/Alignment] Syria's Alawite regime is part of Russia-allied Middle-Eastern Shia axis (Iran/Syria + Shia dominated Lebanon and to an extent, Iraq)
[Geopolitical/Alignment] In contrast, one of Russia's main threats as well as challenges is Wahhabi Sunni Islamism.
Which is pretty much what a majority of anti-Assad rebels consist of.
[Geopolitical/Alignment] USA and Western Europe are anti-Assad and somewhat pro-Rebel.
Thus, Assad is a friend by a virtue of "the enemy of my enemy" even regardless of prior points.
More formally, Russia sees benefit in both thwarting the interests of the West (positioning itslef as a strong power that wins) as well as in simply draining West's resources and attention that would be otherwise occupied somewhere where Russia would rather them not be, like Ukraine.
[Geopolitical/Long game] Russia benefits from instability in Middle East, in that the flood of refugees swamping both Turkey and Western Europe weakens both.
Turkey is Russia's long term geopolitical rival; so's Western Europe. Anything that weakens them is seen as good for Russia.
[Geopolitical/Alliances] By supporting Assad, Russia is creating a precedent (or deepening one, rather) that Russia stands by its friends.
Long term, this helps Russia win allies; as regimes see that Russia is true to those it committed to, and takes meaningful steps to defend them.
(especially cogent in light of USA's late behavior that to many Middle Eastern countries appears the opposite).
[Economic] Al-Assad's regime is one of the big customers of Russian military-industrial complex production.
[Domestic/political] A short, victorious war is a good thing for the popularity, especially of a strongman President.
In Syria, Putin has a win/win situation: he can risk very little (if Assad loses, it can be blamed on Assad); for a rather large political reward (if Assad wins, Putin is seen as the cause in Russia).
Plus, sticking their middle finger up at the West usually plays well with Russian public.
Russia has had a naval base in Syria since the 1970's, which it would like to maintain.
Russia fears that, if Assad lost power, Syria would become anarchic and even more geopolitically destabilizing.
Russia has significant influence over the Assad government which it could scarcely hope to replicate under any other regime.
Russia is a weapons supplier to the Assad govt.
Syria is a strategic ally for Russia. If Assad were to lose power, they risk of losing their only naval base in the Mediterranean sea.
As Russia is completely surrounded by NATO bases, they are trying to maintain the few bases they currently have. That is why Putin is backing Assad, and why U.S is backing rebel/terrorist groups in Syria.