bepaald / signalbackup-tools

Tool to work with Signal Backup files.
GNU General Public License v3.0
790 stars 38 forks source link

Import issue with database version 213 #169

Closed crimsoncor closed 10 months ago

crimsoncor commented 10 months ago

Got two backup files I'm trying to merge. Both are v213 files. I am in the Signal beta program so I'm running 6.42.2 of the app (this may be my issue).

Got latest from git and built this morning

> signalbackup-tools --help
 *** Starting log: 2023-12-17 11:21:04 *** 
signalbackup-tools (signalbackup-tools) source version 20231214.211551

When I try to merge the small file into the big, I get

Getting list of thread id's...
Got: -1

Importing thread -1 (1/1) from source file: travel_signal-2023-12-17-11-03-33.backup
BACKUPFILE VERSION: 1
BACKUPFILE SIZE: 40775596
COUNTER: 2286250312
Reading backup file...
FRAME 6514 (100.0%)... 
Read entire backup file...
done!
Database version: 213
importThread (-1)
Deleted releasechannel recipient from source database (_id: 104)
Failed to get uuid/phone/group_id from source database
[Error]: A fatal error occurred while trying to import thread -1. Aborting

When I try to merge the bigger file into the small I get

Getting list of thread id's...
Got: -1

Importing thread -1 (1/1) from source file: pixel6a_signal-2023-12-17-11-07-21.backup
BACKUPFILE VERSION: 1
BACKUPFILE SIZE: 862118822
COUNTER: 3010475275
Reading backup file...
FRAME 43843 (100.0%)... 
Read entire backup file...
done!
Database version: 213
importThread (-1)
Warning: Source database contains 'remapped_recipients'. This case may not yet be handled correctly by this program!
1 : 88 -> 337

Old id:
(no results)

New id: 
_id|type|e164|aci|pni|username|email|group_id|distribution_list_id|call_link_room_id|registered|unregistered_timestamp|blocked|hidden|profile_key|profile_key_credential|profile_sharing|profile_given_name|profile_family_name|profile_joined_name|profile_avatar|last_profile_fetch|system_given_name|system_family_name|system_joined_name|system_nickname|system_photo_uri|system_phone_label|system_phone_type|system_contact_uri|system_info_pending|notification_channel|message_ringtone|message_vibrate|call_ringtone|call_vibrate|mute_until|message_expiration_time|sealed_sender_mode|storage_service_id|storage_service_proto|mention_setting|capabilities|last_session_reset|wallpaper|wallpaper_uri|about|about_emoji|extras|groups_in_common|avatar_color|chat_colors|custom_chat_colors_id|badges|needs_pni_signature|reporting_token
337|0|+16192543156|4bf108f7-8024-492c-b008-efb42e633fb6|PNI:989a6002-4b7f-43a5-8c32-93c70024e785|(NULL)|(NULL)|(NULL)|(NULL)|(NULL)|1|0|0|0|jy7TpYOPwFO7S/t4FguKOjhJCzS4eigQVhYpCF/3ejU=|CiCPLtOlg4/AU7tL+3gWC4o6OEkLNLh6KBBWFikIX/d6NRKZAQA81d/ <trimmed>

2 : 87 -> 339

Old id:
(no results)

New id: 
_id|type|e164|aci|pni|username|email|group_id|distribution_list_id|call_link_room_id|registered|unregistered_timestamp|blocked|hidden|profile_key|profile_key_credential|profile_sharing|profile_given_name|profile_family_name|profile_joined_name|profile_avatar|last_profile_fetch|system_given_name|system_family_name|system_joined_name|system_nickname|system_photo_uri|system_phone_label|system_phone_type|system_contact_uri|system_info_pending|notification_channel|message_ringtone|message_vibrate|call_ringtone|call_vibrate|mute_until|message_expiration_time|sealed_sender_mode|storage_service_id|storage_service_proto|mention_setting|capabilities|last_session_reset|wallpaper|wallpaper_uri|about|about_emoji|extras|groups_in_common|avatar_color|chat_colors|custom_chat_colors_id|badges|needs_pni_signature|reporting_token
339|0|+16195189538|6d4eaf87-ef80-4734-bbc9-5d5448ab26cf|PNI:8a7b82b9-c15e-4764-9c7e-77a2f9d78aab|(NULL)|(NULL)|(NULL)|(NULL)|(NULL)|1|0|0|0|aEVn9Vl6ZivEVOywlgHPHf2UzMUjPILqiIiniU4HcTI=| <trimmed>
 REMAP RECIPIENTS! 
  Mapping 88 -> 337 (d)
  Mapping 87 -> 339 (d)
Deleted releasechannel recipient from source database (_id: 130)
Failed to get uuid/phone/group_id from source database
[Error]: A fatal error occurred while trying to import thread -1. Aborting
bepaald commented 10 months ago

Oops, so sorry. It seems like I recently commented out a crucial line (while working on #164), should be fixed now. Hopefully that's the only problem. I don't see anything in the beta version that gives problems, but there is some username stuff that I'm not sure about.

Please try again. Thanks!

crimsoncor commented 10 months ago

okay, so that did make it better. There does seem to be an issue with it correct discarding duplicate messages (or maybe duplicate reactions?) when doing a merge. In my case, my large backup contained some, but not all the message from the small backup. So when I did the merge I got a bunch of errors like this

[Error]: After sqlite3_step(): UNIQUE constraint failed: message.date_sent, message.from_recipient_id, message.thread_id
         -> Query: "INSERT INTO message (_id,date_sent,date_received,date_server,thread_id,from_recipient_id,from_device_id,to_recipient_id,type,body,read,ct_l,exp,m_type,m_size,st,tr_id,subscription_id,receipt_timestamp,has_delivery_receipt,has_read_receipt,viewed,mismatched_identities,network_failures,expires_in,expire_started,notified,quote_id,quote_author,quote_body,quote_missing,quote_mentions,quote_type,shared_contacts,unidentified,link_previews,view_once,reactions_unread,reactions_last_seen,remote_deleted,mentions_self,notified_timestamp,server_guid,message_ranges,story_type,parent_story_id,export_state,exported,scheduled_date,latest_revision_id,original_message_id,revision_number) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

before finally failing with

Checking foreign key constraints...
ERROR Foreign key constraint violated. This will not end well, aborting.
      Please report this error to the program author.
-----------------------------
| table    | parent  | fkid |
-----------------------------
| reaction | message | 1    |
-----------------------------
[Error]: A fatal error occurred while trying to import thread 2. Aborting

I was able to get around that by cropping the small backup to only the most recent messages that were not part of the large backup and then everything merged correctly and was happy. So no immediate problems for me, but there does seem to be some sort of newish issue when dealing with duplicate messages and/or reactions

bepaald commented 10 months ago

Ok, this is all expected when merging backups with overlapping content. The tool does no automatic discarding of duplicates (that is non-trivial operation), you need to crop first (as you rightly did in the end). I think I'll update the readme to make that more clear.

The error you got at the end originally is because there is a reaction that references a message that does not exist (because its insert had failed previously with one of the earlier errors).

So, I consider this all working as expected. I'll close this, but do let me know if there is anything else. Thanks for reporting back!

crimsoncor commented 10 months ago

oh good to know. I swear I've merged backups with dupes before but maybe I just got lucky and didn't trigger this edge case.