You'll want to ensure the malware can't destroy your backup, but that is possible too. A traditional way is to have a separate backup machine that runs backup program and pulls files remotely. Some backup apps can store directly to cloud storage and can work with "append only" permissions, to ensure that client can't delete existing backups. In this configuration, a separate trusted machine must run pruning periodically.
oh, btw. "Blockchains solve this" haha.
As for "encrypting your backups", that's what the "check" command is for - it can't ensure that this .py file actually contains python code (and not encrypted data with ransomware message), but it can check that indices are well-formed, and file checksums match the uploaded contents. Obviously it should also be run on trusted machine.
Not sure what this whole "blockchain" comment was about.
The blockchain I mentioned was just a reference to the fact that with hashcodes on everything make corruptions at least detectable, but yeah it wasn't clear what I meant.