Restored backup, Zotero look for PDF in the wrong folder

edited December 5, 2022
I had backed up $HOME/Zotero, formatted, reinstalled Zotero and restored the backup.

Now Zotero is looking for attached PDF files in $HOME/Zotero/storage/ALPHANUMERIC_CODE/pdf_file.pdf, while the PDF files are located in $HOME/Zotero instead.

How can I recover from that?

I cannot even guess the alphanumeric code to put the PDF back where Zotero look for them.

P.S. The folder `$HOME/Zotero/storage/ALPHANUMERIC_CODE` exist, but is empty
  • If I do

    SELECT items.itemID, items.key, itemAttachments.path FROM items INNER JOIN itemAttachments ON items.itemID=itemAttachments.itemID;

    will I obtain the correct path in which files should be?
  • I share here the script I used to repair most of them.

    Unfortunately some "special" characters which are spelled correctly in the database are not spelled correctly in the filename. So something was lost as it is crazy to handle all of them.

    #!/usr/bin/env python
    # coding: utf-8

    import sqlite3
    from pathlib import Path
    import shutil

    con = sqlite3.Connection("/home/USERNAME/Zotero/zotero.sqlite")
    con.row_factory = sqlite3.Row
    cur = con.cursor()

    query = """
    SELECT items.itemID as itemID, items.key as key, itemAttachments.path as path
    FROM items INNER JOIN itemAttachments
    ON items.itemID=itemAttachments.itemID;
    """
    rows = cur.execute(query)

    for row in rows:
    path = row['path']
    if not path:
    continue
    path = path.replace("storage:","")
    key = row['key']
    if not key:
    continue
    pathnorm = path.replace("’","?")
    pathnorm = pathnorm.replace("–", "?").replace('"', "?").replace("‘","?").replace("“","?").replace("Ř","?").replace("ů","?").replace("ř","?")
    pathnorm = pathnorm.replace("Ø","�").replace("ø","�").replace('"','?')
    pathnorm = pathnorm.replace("‐","?")
    pathnorm = pathnorm.replace("á", "�")
    ff = Path(f"/home/USERNAME/Zotero/{pathnorm}")
    if not ff.is_file():
    #print(f"File origin '{ff}' not found")
    continue
    ftdir = Path(f"/home/USERNAME/Zotero/storage/{key}")
    ftdir.mkdir(exist_ok=True)
    ft = ftdir/f"{path}"
    #print(f"Moving '{ff}' -> '{ft}'")
    # shutil.move(src, dst, copy_function=copy2)
    shutil.move(ff, ft)

    con.close()




  • Now Zotero is looking for attached PDF files in $HOME/Zotero/storage/ALPHANUMERIC_CODE/pdf_file.pdf, while the PDF files are located in $HOME/Zotero instead.
    You mean the PDFs were directly in Zotero? Zotero obviously didn't do that — it stores files in the 'storage' subfolders. This is due to something you did, and you'll need to recover from it yourself.
  • > You mean the PDFs were directly in Zotero?

    The PDFs were in $HOME/Zotero

    I also have .js files in $HOME/Zotero, like "Web of Science.js". Those js files are also in the "translators" subfolder. So I deleted them from $HOME/Zotero.

    Now there are some .ppm files in that folder ... How does a "normal" $HOME/Zotero subfolder look like? Or how can I restore it to a normal folder?

    I thought to upload it all and then download it again, but that would require me to buy the unlimited plan.

  • I mean, it just sounds like you did something to make a total mess of your data directory, resulting in all sorts of files being in the root folder that don't belong there. That's not something we can help with.

    Data Directory Contents explains what's supposed to be there.
Sign In or Register to comment.