This function is made to run inside restore script. YunoHost cli restore action defines the var YNH_BACKUP_DIR before to call this helper.
You can’t call it directly inside upgrade script. So if you wan’t restore a file inside your upgrade script you shoulc backup it yourself before the upgrade.