On a schedule, the scenario picks up new files from S3 and copies them into S3. Your backup keeps itself.
Automating Nextcloud and S3 takes no code: a ready-made scenario does the routine for you.
You can launch this Nextcloud + S3 integration in Scriptera: describe the task in plain words — the scenario is built, launched and monitored for you.