I did that, if someone else is interested:
Edit 2022-05-10: Moved from Github Gists to proper Github repository.
Just change BACKUP_DIR to whatever is suitable in your situation. Flash wear wise, I feel comfortable to backup it to internal flash every 6 hours, your opinion might differ.