Cyanogen Mod on the Sony Xperia Z2 and LG Nexus 5

I have a question regarding installing Andrid Cyanogen Mod on two phones, the Sony Xperia Z2 and the LG Nexus 5. When I install the OS on the devises, is there a way for me to make a backup on the original OS on the phones, mainly due to warranty concerns. Or can i reinstall the different android versions some other way if I need to switch back later on? 

Thank ye kindly for any response.

In order to install CM, you'd need a custom recovery, either ClockWorkMod (CWM) or Team Win Recovery Project (TWRP). With either one, you have the option to make a backup, which will copy the entire system. Once you're done, you can just flash your original stock image.

I know with Samsung phones, there is a program called Odin, which would allow you to flash the stock firmware, which includes the stock recovery. However, in order to combat people just flashing stock for warranty purposes, manufacturers, such as Samsung, have implemented "flash counters", which void the warranty if tripped. There are ways to reset said flash counter, so really, it's best to look up all this under the appropriate forum, such as the Xperia Z2 sub-forum over at XDA.

I'd imagine since Sony got the most developer friendly manufacturer award from XDA, and Nexus phones are designed to customized, it should be a matter of flashing a custom recovery via ADB, and make a backup before flashing CyanogenMod.