You could do it as James suggested, but as far as I understand you need dynamic rules that are activated when the main wan goes down.
The only way to it, is adding on-the-fly rules using a script inside the
wan-uplink-update event (
It's not easy, and it requires a little of programming skills and iptables knowledge.
My advice is to simply the whole configuration, and give low priority to all non-important users using the traffic shaping feature.