Saving and restoring of many flags(variables)
Solution 1:
Store the values in armor stands and switch the armor stands' name when saving and loading a state.
The armor stands' name will be n, where N equals the id of the set. When using the data pull it from set 0 and when saving/loading switch the names of the desired set with set 0.
Switch sets:
/entitydata @e[type=ArmorStand,name=0] {CustomName:9999}
/entitydata @e[type=ArmorStand,name=<id of desired set>] {CustomName:0}
/entitydata @e[type=ArmorStand,name=9999] {CustomName:<id of desired set>}