Should I write a recommendation letter for a student at a previous job/institution? I receive requests for recommendation many times, but I have received one from a student belonging at a previous affiliation of mine, asking for a favourable letter in view of their achievements.

I am aware of the fact that if I comment on the performance of the student, it could be used against me, since it is good practice to "erase" all the material, marks, personal information of the students and staff relationship at a previous job. So I am hesitant to go in that direction. On the other hand, I could comment only very generally on the skills of the student, which could backfire their application to a new job

Differently from this question I am not looking for a recommendation, but giving one...
When you change job, you don’t erase your memory (well, not in all jobs), nor do you all your responsibilities related to this previous job vanish. It is true that leaving a position creates certain obligations in the data you can retain, and how you can use non-publicly available information pertaining to your older institution. However, in the particular case of a reference letter, I don't think it should cause trouble. Moreover, reference letters are confidential.

Actually, I'd go further than saying it should not be a problem. In fact, I think if you can honestly write him a good recommendation letter, it is part of your responsibility to do it. This responsibility is not to your former institution, but to the student and the academic system as a whole.