Skip to Main Content

Restoring a Sharkey YunoHost database backup manually

3 minutes

This guide mainly focuses on restoring the YunoHost app for Sharkey's backed up PostgreSQL database, although with enough adjustments, this should also work with other apps that also use PostgreSQL.

On the evening of the 31st May, 2025, Hajiku had a downtime that was caused due to a failed YunoHost update. Now usually, YunoHost backs apps up before update, including the PostgreSQL database, but unfortunately, YunoHost does not know how to restore the database properly.

Some people on GitHub have also had the same issue with the Sharkey YunoHost app unfortunately, and I don't quite have an easy way to explain stuff like this, so here we are

So now, we're going to show you a guide on how to get your instance back.

Step 1: Obtain the backup file

Do so by going to the YunoHost admin panel (https://example.tld/yunohost/admin) and making sure you're signed in.

Then, proceed to navigate to:

Backup > Local archives

and locate the most recent backup that is named either sharkey-pre-upgrade1 or sharkey-pre-upgrade2

Image telling you to first restore the backup then download the archive

First, make sure to uninstall the faulty Sharkey installation and restore this backup by either clicking on "Restore" as shown in the screenshot, or by running the following:

sudo yunohost backup restore sharkey-pre-upgrade#

Replace # with the proper backup ending (either 1 or 2)

After that, go to the page again and click on "Download"

You are then going to proceed to open your File Manager and extract the archive. Locate the database inside of the archive by going to "(Extracted Folder)/apps/sharkey/backup/db.sql"

Proceed to upload this file to your YunoHost server in any path that can be accessible by the postgres user, using any method. Personally, I transferred it over using Wormhole to /tmp/ (mainly as /tmp/db.sql)

Step 2: Delete empty database and recreate new one

Warning

BEFORE PROCEEDING, MAKE SURE THAT THE sharkey SERVICE IS NOT RUNNING! You can stop it with either command:

sudo systemctl stop sharkey

sudo yunohost service stop sharkey

or by navigating the web admin panel:

Tools > Services > sharkey > Stop

The new database should in theory be empty either way, so it should be safe to delete the target (newer) one.

Now enter the PSQL shell with the following command:

sudo -u postgres psql

And enter the following commands in the SQL shell:

DROP DATABASE sharkey; -- Drops the new database
/* If commands fail due to still connected users, run the following:
REVOKE CONNECT ON DATABASE sharkey FROM public;
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'sharkey';
DROP DATABASE sharkey;
*/
CREATE ROLE pgadmin; -- Assure the pgadmin role exists
CREATE ROLE sharkey; -- Assure the sharkey role exists
CREATE DATABASE sharkey OWNER sharkey; -- Create completely blank database
\q -- Quit PSQL

Step 3: Restoring .sql file

After that, proceed to restore the found SQL database into the new empty one by running the following:

sudo -u postgres psql -d sharkey -f /path/to/db.sql

Make sure to observe for errors while it imports. If any occur, try looking online for solutions!!

Step 4: Starting Sharkey and verifying state of server

Now we have practically made it to the end.

The final step is to start up the Sharkey instance.

You can start it with either command:

sudo systemctl start sharkey
sudo yunohost service start sharkey

or by navigating the web admin panel:

Tools > Services > sharkey > Start

That's pretty much it for this guide, thanks for reading!

-kevadesu