Vue lecture

How to restore the deleted records [Command line method]


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

  •  

Koha is running in CGI mode. This is a security issue!


Koha is running in CGI mode. This is a security issue! Run Koha using Plack for CSRF (cross-site request forgery) protection. More information: koha-plack --help.

This warning message appears in the Koha > About > Server Information section. Here is the reason to show the message and the solution to fix it.

Essentially, your library system is telling you that its engine is outdated and vulnerable to hackers.

The Problem

Koha is currently running on CGI. Think of CGI like an old-fashioned clerk who has to restart their entire computer every time a customer asks a single question. It’s slow, but more importantly, it lacks the security guards needed to verify that a request is legitimate.

Because of this, your system is at risk for CSRF (Cross-Site Request Forgery). This is a trick where a hacker sends a fake link that, if clicked by a librarian, could force the system to delete books or change settings without anyone realising it.

The Solution: Plack

The error message is telling you to switch to Plack. Plack is like a modern, 24/7 security team that stays "awake" and checks every visitor’s ID to make sure they aren't being tricked by a hacker.

How to fix it

Need to switch from CGI to Plack. Here are the commands to enable Plack. Here library instance name is library.

sudo koha-plack --enable library
sudo a2enmod headers proxy_http
sudo koha-plack --start library
sudo service apache2 restart

The error message will vanish, your staff pages will load much faster, and your data will be much safer from web-based attacks.

  •  

How to read Koha error logs using the Tail command

If you manage a Koha Library Management System, you will eventually run into a "500 Internal Server Error" or a screen that simply won't load. When this happens, the Koha error logs are the best assistant. The Linux system records events like a personal diary. It tells exactly what went wrong and where.

The most efficient way to watch these errors in real time is to use the tail command in the Linux terminal. Here are simple instructions on how to do it.


Location of the log files

In a standard Koha installation (on Debian or Ubuntu), the logs are stored in /var/log/koha/. Inside that folder, each "instance" (your library's specific setup) has its own directory.
The most important log file is usually plack-error.log or koha-error.log.
The general path looks like this: /var/log/koha/instancename/plack-error.log
Before using the command, find the Koha instance name. The following command will help you find the instance name.

sudo koha-list

Using the tail command

The tail command shows you the last few lines of a file. This is perfect for logs because the newest errors are always added to the bottom.

To see the last 20 lines
If you just want a quick snapshot of the recent activity, type: 

sudo tail -n 20 /var/log/koha/library/plack-error.log

To watch errors live (The "-f" switch)
This is the most helpful tool for troubleshooting. The -f stands for follow. It keeps the file open and updates your screen the exact second a new error occurs.

sudo tail -f /var/log/koha/library/plack-error.log

While this command is running, go to your Koha staff interface and refresh the page that is causing the error. You will see the technical details pop up instantly in your terminal.

When you are finished reading the logs and want to go back to the regular command prompt, simply press Ctrl + C

Reading logs might seem confusing at first, but it is the fastest way to fix Koha issues. Instead of guessing why a page isn't working, use tail -f and let the system tell you exactly what is broken.
  •  

Formations proposées par KohaLa

Tous les ans, KohaLa propose des formations.Ces formations sont gratuites pour les adhérents. Elles n’ont pas vocation à remplacer les formations initiales proposées par les prestataires, mais sont complémentaires.Les formations sont assurées par des formateurs bénévoles. Les thématiques peuvent donc dépendre des bonnes volontés disponibles ! Voici quelques exemples de formations proposées : rapports SQL, […]

The post Formations proposées par KohaLa first appeared on Association KohaLa.

  •  

Un symposium, c’est quoi ?

Chaque année, KohaLa organise son symposium. Ce rendez-vous est l’occasion de se rencontrer, utilisateurs de Koha actuels ou futurs, adhérents à l’association ou non. Au programme : analyses des nouvelles versions de Koha, mise en avant de fonctionnalités spécifiques mises en place par des établissements, retours d’expérience, découverte et prise en main d’outils communautaires… Mais […]

The post Un symposium, c’est quoi ? first appeared on Association KohaLa.

  •  

Un hackathon c’est quoi ?

Tous les ans, KohaLa organise, traditionnellement au mois de janvier, un « hackathon ». Cet événement s’apparente à un marathon de développement. Des utilisateurs de Koha et des développeurs se retrouvent pendant deux jours pour réfléchir aux évolutions de Koha, modifier, tester, faire des erreurs parfois…  Les sujets peuvent être variés : financement de développements, traduction, sessions […]

The post Un hackathon c’est quoi ? first appeared on Association KohaLa.

  •  

Hackathon 2026

Le Hackathon 2026 organisé par l’association Kohala se déroulera les 12 et 13 janvier 2026 (9h-12h, 14h-17h) à l’Université Lyon 3 – BU de la Manufacture des tabacs (6 rue Professeur Rollet, 69008 Lyon. Transports : Métro D ; Bus C5, C7, 69, T4) Si vous souhaitez participer à l’un des deux ateliers proposés, merci […]

The post Hackathon 2026 first appeared on Association KohaLa.

  •