Local backup eka ransomware ekakin kela unoth ewa sync wela online onedrive backup ekat yaida bn ? 
The simple answer is that a Cloud storage is vulnerable as it syncs with your local data.
When ransomware hits you, it's going to encrypt your local data and when your sync engine runs, the cloud gets affected - But it depends on the features that your cloud storage facilities provides too.
The way around this is versioning. In simple terms having versioning enabled, makes the existing data immutable. Any change will result in a new version, and hence, even after the encryption, the encrypted data will be held as a new version. So it's easy to recover the old data.
Microsoft didn't earlier had the versioning facility with the OneDrive. Only the Business edition of the OneDrive had. But I believe from mid 2018, they enabled it on all OneDrive editions mainly because of ransomware. Dropbox too has versioning.
Many cloudstor systems have their own detection mechanisms in place to monitor abnormal activity like encryption and inform the user. Even Microsoft has this on their OneDrive.
You got to note the following imortant facts.
Old type backups that to copy onto another internal drive or a
permanently attached external drive are
useless in a ransomware attack. This is only helpful in a hardware failure.
It's a good practice to keep your network backup disconnected or offline after the backup.
Always rely on versioning. Vesioning is the
key lifesaver with a ransomware infection.