It seems like the restore_create_users function in backup/restorelib.php is escaping user data too many times. Which results in having extra '\' characters in user field.
Reproduction:
1. On one moodle instance create a test course and a test user with lastname being o'reilly. Then make this user a student of the course. Create a backup of this course and ask for course users to be exported.
2. On another moodle instance restore this course with its users, make sure that this moodle instance doesn't have a user with the same username, so that it will actually create a new user.
3. After that browse the moodle user list and search for your user. In the user details you will see that its lastname has become o\'reilly.
The problem seems to happen on any user field. It seems that the function restore_create_users is calling addslashes twice to escape user information. Once at line 2812 when calling backup_todb function, and another time before inserting the new record at line 3015 when calling addslashes_recursive.
I have attached a patch to this problem that fixes it.