Shutdown script and backups

I always use the “shutdown” menu option and wait for that to complete before I power down my Lakka RPi4. That should be safe.

Recently, I noticed one of my highscore tables got corrupted. Hopefully, it’s only one of them. I don’t think the RPi4 ever lost power or was shutdown “unsafely” but something happened anyway. I want to make regular backups of the savefiles folder to help protect the files.

Is there a way to run a script when I choose “Shutdown” from the menu?

My idea is to run a backup script at boot (crontab) and shutdown.