One suggestion on the script, inside the while block, include the following code:
/* Need to re-initialize all variables*/
Select @dbName = null
, @db_bkpdate = null
, @media_set_id = Null
, @backupsize = Null
, @filepath = Null
, @filestatus = Null
, @fileavailable = Null
, @status = Null
, @backupsize = Null
If not, and there are missing backups, some of the data displays incorrectly. Aside from that tiny suggestion, thank you for the code, it is helpful.