When backing up and restoring a course with a course completion tracking role, the role appears in mdl_course_completion_criteria as zero. This causes an error that breaks course access for anybody enrolled in the course.
The problem does not occur if the course is backed up with user data and some user has the completion tracking role.
Part of the problem, at least, appears to be that the role does not get into roles.xml in the backup file due to the order of the steps in backup_final_task. When I moved backup_final_roles_structure_step further down, the role appeared in roles.xml. That did not solve the problem completely, however, so something else is going on.