When you delete a record, Koha doesn't immediately erase it from the database; it moves it to a deleted table. These are the tables where deleted records are stored: deletedbiblio, deletedbiblio_metadata, deletedbiblioitems, and deleteditems.
Find the deleted Information
Since the records are no longer in the main catalogue, you need to look in the trash tables. The best way to do this is to run a simple report.Go to Reports > Guided Reports > Create from SQL.
Give it a name like Find Deleted Records.
Paste this SQL query to see everything in the trash:
SELECT biblionumber, title, author FROM deletedbiblio
Run the report and find the biblionumber of the records you deleted. Only a few numbers, write those numbers down.
Restoring the records
In Koha, a catalogue record is not stored in a single table but is split across several linked tables to separate the general bibliographic details from specific editions and individual physical copies. Here are the primary tables where catalogue record data is stored:biblio (The Core Record): This is the parent table. It stores the primary descriptive information that remains constant across editions and physical copies. It stores: Title, Author, Series title, Notes, and Abstract.
The key field is biblionumber, the unique ID that links all other tables.
biblio_metadata (The MARC Data): This table holds the actual raw MARC (Machine-Readable Cataloguing) record. It stores the full MARCXML structure of the record. This includes all the tags like 245$a (Title), 100$a (Author), and even the hidden 880 tags (Alternate Graphic Representation).
biblioitems (The Edition/Format Layer): This table sits between the general bibliography and the physical items. It defines how the work was published. It stores: ISBN, ISSN, Publication Place, Publisher, Publication Date, Edition statement, and Item Type (e.g., Book, DVD).
items (The Physical Copy Layer): This table stores data for every individual book or piece of media sitting on the shelf. What it stores: Barcode, Call Number, Home Library, Current Location, Cost, Public/Private Notes, and Circulation Status (e.g., Withdrawn, Lost).
The key field is itemnumber.
Since you have been restoring records, remember that if you only restore the biblio table, your catalogue will have the title but no physical books or MARC details. For a broken record to be fully functional again, data must exist in all four of these tables.
Log in to MariaDB
Log in to MariaDB and enter the Koha database.
sudo mysql -uroot -p
use koha_library;
Restore the biblio table first. Also need to restore corresponding records in biblioitems and items from their respective deleted tables to ensure the catalogue functions correctly. Ensure biblionumbers do not already exist in the biblio table, or the query will fail due to primary key constraints.
To correctly move these records back into the tables, use the IN operator. Here is an example of inserting the biblionumber 177022. Apply the queries in the following order.
-- Restore biblio
INSERT INTO biblio SELECT * FROM deletedbiblio WHERE biblionumber = '177022';
-- Restore metadata
INSERT INTO biblio_metadata SELECT * FROM deletedbiblio_metadata WHERE biblionumber = '177022';
-- Restore biblioitems
INSERT INTO biblioitems SELECT * FROM deletedbiblioitems WHERE biblionumber = '177022';
-- Restore items
INSERT INTO items SELECT * FROM deleteditems WHERE biblionumber = '177022';
Want to restore more biblionumbers in a single stretch, mention the ID numbers; e.g.
INSERT INTO biblio
SELECT * FROM deletedbiblio
WHERE biblionumber IN (
176340, 176341, 176858, 176861, 176874, 176875, 176884, 176887,
176890, 176893, 176894, 176895, 176896, 176897, 176898, 176900,
176901, 176902, 176903, 176909, 176911, 176916, 176921, 176929,
);
Rebuild the search index (Zebra or Elasticsearch) to display the restored records in the search result. Apply the following command in a terminal to rebuild the search index:
sudo koha-rebuild-zebra -v -f library

No comments:
Post a Comment