it depends on the details, but regardless, you have to generate the list of commands from some place; the msdb backup history from production, or the folder full of files, or some other method.
it gets more complex depending on what you need to do...last full backup, or do you need to applu full/diff/log backups on a per database bassis...that's going to depend on naming conventions, most likely.
this link was one of the first i googled that had a decent example; this is assumine one full backup per database exist sint he folder:
the more info you provide, the more we can help you.
Lowell