Restoring DB Document from Backup

Viewing 1 reply thread
  • Author
    Posts
  • August 27, 2017 at 7:52 PM #24215

    Mike Schwartz
    Participant

    Brendan,

    I managed to munge up my database document and needed to restore from a backup file on my Mac. Here’s what I did:

    1. Disabled iCloud Sync, and clicked “Delete from iCloud”. That was to avoid reintroducing the same damage that I was attempting to revert back from.
    2. Quit Tap Forms.
    3. Identified my most recent “safe” backup in my backup folder, ~/Library/Containers/com.tapzapp.tapforms-mac/Data/Documents/Backups.
    4. Deleted all later backup files, assuming they were contaminated.
    5. Deleted my current database document, Mike’s Custom Forms.tapforms.
    6. Unzipped the backup file, resulting in a new file named Mike’s Custom Forms.tapforms. Moved this file up one level to the Documents folder.
    7. Launched Tap Forms, which automatically opened Mike’s Custom Forms. Everything looked OK.
    8. Re-enabled iCloud Sync.

    I’m getting to my questions, really!

    9. Next thing I did was launch Tap Forms on my iPhone. My most-frequently used form showed 72 records on the iPhone, compared to 74 records on the Mac. Not surprising — I don’t use the phone app that much and could easily imagine that my two most recent records had never been synced to the iPhone.
    10. I waited for Records 73 and 74 to download to the iPhone, but it didn’t happen. I confirmed that the database ID numbers matched between the Mac and the iPhone. I disabled sync on the iPhone and then re-enabled it. I still never got the two missing records.
    11. Then I tried an experiment by making a small edit on my Mac to Record 73 — a minute later that record appeared on my iPhone. Did the same thing with Record 74, and it also came right across the to phone.

    QUESTION 1: Why didn’t the final two records come across to the iPhone on their own, without my having to nudge them along by making gratuitous edits on the Mac side? Is it possible that I just didn’t wait long enough? My DB document is about 260 MB. As I mentioned, the two missing records popped over almost immediately after I made the minor edits.

    QUESTION 2: Here’s a hypothetical scenario. Suppose I had used Tap Forms on the iPhone after having done the aforementioned munging on the Mac, and the same damage (undesired changes) got synced to the iPhone. Then I follow Steps 1-8 above, resulting in a successful restoral on the Mac. Now what will happen when I launch Tap Forms on the iPhone? Will the Sync system see the “damaged” records on the iPhone as more recent changes and push them up to iCloud and then back down to my just-restored Mac document, essentially negating my restoral efforts?

    Thanks,
    Mike

    August 28, 2017 at 1:49 AM #24219

    Brendan
    Keymaster

    Answer 1: When Tap Forms uploads to CloudKit, it decides which objects to upload by retrieving a stored sequence number that’s then used to fetch objects from the database which have a sequence number greater than the last stored sequence number. Whenever you make a change to the database, a new sequence number is generated and stored with every object. I can ask the database what it’s last sequence number is. When I’m done syncing, I store that last sequence number to the .plist file embedded within the .tapforms package.

    I needed to explain that because one theory that I have could be that occasionally the objects don’t get properly uploaded to the CloudKit servers but the last sequence number is still stored in the .plist file. So Tap Forms essentially misses those objects because it didn’t re-send them and thought that it had already sent them. That’s just a theory.

    The code for syncing is quite complex with lots of threading and operations and notifications and stuff.

    Answer 2: You might be better off copying the backup to all your devices before you re-e enable sync. Or delete them from the other devices, then enable sync again on the primary device and then open up the placeholder documents once the original device has finished syncing completely.

Viewing 1 reply thread

You must be logged in to reply to this topic.