Add lost metadata from backup to cards


While experimenting and improving with different features (addons, changing notetypes etc.) of Anki, I somehow lost the history metadata step by step of a large part of the cards. They are now considered as “new” by Anki. Unfortunately I was not aware of the loss of the metadata for a long time.
I don`t want to backup to loose all the improvements.

Is there any easy way to export the cards with (!) metadata to LibreOfficeCalc/Excel, change them and then reimport them to Anki?

My idea:
Correct current cards outside Anki in Calc/Excel with cards from backup based on the card name and/or “added date” (both should be enough to identify) and import again.

Please don`t spend too much time in answering. Just give me a hint if there is any easy way for an amateur like me.

Best regards

You can do this if you have changed only the notetype of the cards in question, and not things within the fields, or the fields themselves.

  1. Import the backup in another profile.
  2. Duplicate the note template for deleted-metadata cards, and name it something different, preferrably.
  3. Select the deleted-metadata cards, change their template to this duplicate template.
  4. Tag them all with some tag so that you can find them later.
  5. Export them as apkg with scheduling.
  6. Delete the deleted-metadata cards from your original profile, then import the ones you exported in step 5.
  7. Change their notetemplate back to the original note-template, taking care to match fields and whatnot.

You could maybe do it without the changing of the notetypes and all, but I’m not certain about how anki’s importing and merging thing works anymore.



Thank you for answering.
I am afraid I have changed and added fields to the notetype.

It could still work, have a look at the dialog that comes up when you change a notetype.
It asks you which field in the new notetype, will each field from the old notetype be transferred to. So as long as you know which fields you changed to what, and the contents of the fields have not changed, you could still achieve what you want.

But if you can’t: you can use a SQL Viewer, (I’ve used DB Browser for SQLite, previously) to transfer all the scheduling data from the backedup cards to the modified cards.

I don’t really know SQL well, but I got around fairly well with googling around and trying things.
You’ll have to open the Table called cards.

The id column you see on the left is unique for every card, and I think every column after the “usn” field is the scheduling information.

So you’ll have to import both databases into the viewer. (I suggest exporting the needed cards only and unzipping the apkgs, and opening the db2 files in the viewer.)
Then use sql to match the rows in both databases using their ids and then copying all the columns.

(Actually once you open them in the viewer, it’s quite possible to export them into a csv and use excel or whatever you’re comfortable with, because you’ll be working with only two tables.)

Changing the note template (item 7) deletes the history data and I don’t know how to avoid that.

Is there any easy way besides learning the SQL thing?

On which file you are working with the SQL-Browser? Cannot open .apkg-file with SQL-Browser.

use something like 7zip or winrar to open the apkg, then open the .db2 file you find inside with the sql viewer

I am sorry: I have opened .apkg file with 7zip, but cannot find any .db2 file inside the directory nor in the unzipped directory.

Same with winrar.

Yep, that’s my fault actually; db2 files are found somewhere else.
Try opening the file called collection.anki2

It is my fault. I did not understand the table “Templates” at bottom of popup window “Change note Type” and chose all cards to “nothing”.

Look here

Anyway, now I need to find a way to transfer the history data from backup to the actual cards.

After some fiddling due to different notetypes in different decks, it worked perfectly.
Thank you!

1 Like