How can I tell when OneDrive has finished syncing before running a backup?

I’m using Windows 11 with OneDrive syncing files to my PC. I have a scheduled task that copies those files to an external drive every night, but sometimes OneDrive is still downloading or updating files when the backup starts.I’ve tried adding a delay to the scheduled task, but sync times vary depending on how many files have changed.

Is there a reliable way to check whether OneDrive has finished syncing before allowing the backup script to run?