# Manually verify import content on database file

**URL:** <https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894>\
**Category:** Kolibri\
**Created:** [November 8, 2018, 10:41pm UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894 "2018-11-08T22:41:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryan\_Fisher](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/bryan_fisher/32/160_2.png) [@Bryan\_Fisher](https://community.learningequality.org/u/Bryan_Fisher)\
**Post date:** [November 8, 2018, 10:41pm UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/1 "2018-11-08T22:41:19Z")

</div>

Good day,

I have seen some disk “sqlite3.DatabaseError: database disk image is malformed” errors on kolibri installations. Is there a way to repair or run a command to fix this error?

Thank you kindly.

---

<div class="post-metadata">

**Author:** ![jredrejo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/jredrejo/32/561_2.png) [@jredrejo](https://community.learningequality.org/u/jredrejo)\
**Post date:** [November 9, 2018, 8:20am UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/2 "2018-11-09T08:20:09Z")

</div>

Hi Bryan, you can find the instructions to [fix the malformed database](https://kolibri.readthedocs.io/en/latest/manage/get_support.html#malformed-database) in Kolibri user guide.

---

<div class="post-metadata">

**Author:** ![Bryan\_Fisher](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/bryan_fisher/32/160_2.png) [@Bryan\_Fisher](https://community.learningequality.org/u/Bryan_Fisher)\
**Post date:** [November 9, 2018, 8:34am UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/3 "2018-11-09T08:34:40Z")

</div>

Hi @jredrejo,

After running the two commands, (this is usually the command we use when you get the error message when your db is corrupted after updating to a new kolibri version), but please see the output below after rebooting:

kolibri@tsp:~$ sqlite3 ~/.kolibri/db.sqlite3 .dump | sqlite3 fixed.db  
kolibri@tsp:~$ cp fixed.db ~/.kolibri/db.sqlite3  
kolibri@tsp:~$ sudo reboot now  
Connection to 172.18.0.2 closed by remote host.  
Connection to 172.18.0.2 closed.  
[~/Documents] $ ssh [kolibri@172.18.0.2](mailto:kolibri@172.18.0.2)  
[kolibri@172.18.0.2](mailto:kolibri@172.18.0.2)’s password:  
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-138-generic x86\_64)

- Documentation: [https://help.ubuntu.com](https://help.ubuntu.com)
- Management: [https://landscape.canonical.com](https://landscape.canonical.com)
- Support: [https://ubuntu.com/advantage](https://ubuntu.com/advantage)

0 packages can be updated.  
0 updates are security updates.

New release ‘18.04.1 LTS’ available.  
Run ‘do-release-upgrade’ to upgrade to it.

Last login: Fri Nov 9 10:20:09 2018 from 172.18.0.254  
kolibri@tsp:~$ kolibri status  
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base  
Stopped (1)  
kolibri@tsp:~$ kolibri start  
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base  
INFO Sqlite database Vacuum finished.  
INFO Running update routines for new version…

0 static files copied to ‘/var/kolibri/.kolibri/static’, 770 unmodified.  
Operations to perform:  
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions  
Running migrations:  
No migrations to apply.  
Installed 2 object(s) from 1 fixture(s)  
INFO Importing ContentTag data  
INFO Importing ContentNode\_tags data  
INFO Importing ContentNode\_related data  
INFO Importing ContentNode\_has\_prerequisite data  
INFO Importing ContentNode data  
INFO Importing Language data  
INFO Importing File data  
INFO Importing LocalFile data  
INFO Importing AssessmentMetaData data  
Traceback (most recent call last):  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1193, in \_execute\_context  
context)  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/default.py”, line 509, in do\_execute  
cursor.execute(statement, parameters)  
sqlite3.DatabaseError: database disk image is malformed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):  
File “/usr/bin/kolibri”, line 9, in   
load\_entry\_point(‘kolibri==0.11.0’, ‘console\_scripts’, ‘kolibri’)()  
File “/usr/lib/python3/dist-packages/kolibri/utils/cli.py”, line 664, in main  
start(port, daemon=daemon)  
File “/usr/lib/python3/dist-packages/kolibri/utils/cli.py”, line 273, in start  
update()  
File “/usr/lib/python3/dist-packages/kolibri/utils/cli.py”, line 253, in update  
update\_channel\_metadata()  
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/annotation.py”, line 46, in update\_channel\_metadata  
import\_channel\_from\_local\_db(channel\_id)  
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel\_import.py”, line 675, in import\_channel\_from\_local\_db  
import\_manager.import\_channel\_data()  
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel\_import.py”, line 522, in import\_channel\_data  
raise e  
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel\_import.py”, line 513, in import\_channel\_data  
unflushed\_rows = self.table\_import(model, row\_mapper, table\_mapper, unflushed\_rows)  
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel\_import.py”, line 371, in table\_import  
result = self.raw\_attached\_sqlite\_table\_import(model, row\_mapper, table\_mapper, unflushed\_rows)  
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel\_import.py”, line 292, in raw\_attached\_sqlite\_table\_import  
self.destination.session.execute(text(query))  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/orm/session.py”, line 1176, in execute  
bind, close\_with\_result=True).execute(clause, params or {})  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 948, in execute  
return meth(self, multiparams, params)  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/sql/elements.py”, line 269, in \_execute\_on\_connection  
return connection.\_execute\_clauseelement(self, multiparams, params)  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1060, in \_execute\_clauseelement  
compiled\_sql, distilled\_params  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1200, in \_execute\_context  
context)  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1413, in \_handle\_dbapi\_exception  
exc\_info  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/util/compat.py”, line 265, in raise\_from\_cause  
reraise(type(exception), exception, tb=exc\_tb, cause=cause)  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/util/compat.py”, line 248, in reraise  
raise value.with\_traceback(tb)  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1193, in \_execute\_context  
context)  
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/default.py”, line 509, in do\_execute  
cursor.execute(statement, parameters)  
sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed [SQL: ‘REPLACE INTO content\_assessmentmetadata (id, assessment\_item\_ids, number\_of\_assessments, mastery\_model, randomize, is\_manipulable, contentnode\_id) SELECT source.id, source.assessment\_item\_ids, source.number\_of\_assessments, source.mastery\_model, source.randomize, source.is\_manipulable, source.contentnode\_id FROM sourcedb.content\_assessmentmetadata AS source’] (Background on this error at: [http://sqlalche.me/e/4xp6](http://sqlalche.me/e/4xp6))  
kolibri@tsp:~$ kolibri status  
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base  
Stopped (1)  
kolibri@tsp:~$

---

<div class="post-metadata">

**Author:** ![jredrejo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/jredrejo/32/561_2.png) [@jredrejo](https://community.learningequality.org/u/jredrejo)\
**Post date:** [November 9, 2018, 9:13am UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/4 "2018-11-09T09:13:43Z")

</div>

Hi, it seems the automatic repair has not worked.  
If your database does not contain confidential data, can you attach the `~/.kolibri/db.sqlite3` file here so I can take a look?

One side note: you don’t need to reboot the whole server after doing the db repair commands,  
`sudo service kolibri restart`  
will restart Kolibri.

---

<div class="post-metadata">

**Author:** ![Bryan\_Fisher](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/bryan_fisher/32/160_2.png) [@Bryan\_Fisher](https://community.learningequality.org/u/Bryan_Fisher)\
**Post date:** [November 9, 2018, 9:37am UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/5 "2018-11-09T09:37:40Z")

</div>

Hi,

I will upload the db file shortly.

Thanks for the side not. 🙂 I like to start fresh and be sure everything is intact, hence the reboot 🙂

---

<div class="post-metadata">

**Author:** ![Bryan\_Fisher](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/bryan_fisher/32/160_2.png) [@Bryan\_Fisher](https://community.learningequality.org/u/Bryan_Fisher)\
**Post date:** [November 9, 2018, 9:59am UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/6 "2018-11-09T09:59:10Z")

</div>

Hi,

Please see link with db file.

> **[db.sqlite3](https://drive.google.com/file/d/1CT0c-tJvll46-YAmIr-2RTu4dccIHzbe/view?usp=drive_open)**
>
> Google Drive file.

Please let me know.

Thank you.

---

<div class="post-metadata">

**Author:** ![Bryan\_Fisher](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/bryan_fisher/32/160_2.png) [@Bryan\_Fisher](https://community.learningequality.org/u/Bryan_Fisher)\
**Post date:** [November 9, 2018, 10:38am UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/7 "2018-11-09T10:38:55Z")

</div>

Hi @jredrejo

Don’t look into this any further, I will let you know on an update.

I was troubleshooting and wanted to know which Django version is installed. I switched to root user and ran the command: “kolibri manage import django” then the below output was displayed. It might be a permission error where kolibri user might not have all the needed permissions.

I am re-installing the image and starting from scratch. I will let you know the outcome and what the error was. [I don’t want you to waste unnecessary time due to my uncertainty].

oot@tsp:/var/kolibri# kolibri manage import django  
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base  
INFO Kolibri running for the first time.  
INFO We don’t yet use pre-migrated database seeds, so you’re going to have to wait a bit while we create a blank database…

Operations to perform:  
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions  
Running migrations:  
Applying kolibriauth.0001\_initial… OK  
Applying contenttypes.0001\_initial… OK  
Applying admin.0001\_initial… OK  
Applying admin.0002\_logentry\_remove\_auto\_add… OK  
Applying contenttypes.0002\_remove\_content\_type\_name… OK  
Applying auth.0001\_initial… OK  
Applying auth.0002\_alter\_permission\_name\_max\_length… OK  
Applying auth.0003\_alter\_user\_email\_max\_length… OK  
Applying auth.0004\_alter\_user\_username\_opts… OK  
Applying auth.0005\_alter\_user\_last\_login\_null… OK  
Applying auth.0006\_require\_contenttypes\_0002… OK  
Applying auth.0007\_alter\_validators\_add\_error\_messages… OK  
Applying auth.0008\_alter\_user\_username\_max\_length… OK  
Applying content.0001\_initial… OK  
Applying content.0002\_channelmetadatacache\_last\_updated… OK  
Applying content.0003\_auto\_20170607\_1212… OK  
Applying content.0004\_auto\_20170825\_1038… OK  
Applying content.0005\_auto\_20171009\_0903… OK  
Applying content.0006\_auto\_20171128\_1703… OK  
Applying content.0007\_auto\_20180212\_1155… OK  
Applying content.0008\_contentnode\_coach\_content… OK  
Applying content.0009\_auto\_20180410\_1139… OK  
Applying content.0008\_auto\_20180429\_1709… OK  
Applying content.0010\_merge\_20180504\_1540… OK  
Applying content.0011\_auto\_20180907\_1017… OK  
…  
…  
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style\_guide/static/style\_guide\_module/style\_guide\_module-0.11.0.js’  
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style\_guide/static/style\_guide\_module/style\_guide\_module0.9.0b3.dev+git-5-g1c6ec06.css.dpkg-new’  
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style\_guide/static/style\_guide\_module/style\_guide\_module0.8.0b2.css.dpkg-new’  
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style\_guide/static/style\_guide\_module/style\_guide\_module-0.8.0b1.dev+git-161-g3db1e6f.js.dpkg-new’  
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style\_guide/static/style\_guide\_module/style\_guide\_module0.11.0.css’

767 static files copied to ‘/root/.kolibri/static’.  
Operations to perform:  
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions  
Running migrations:  
No migrations to apply.  
Installed 2 object(s) from 1 fixture(s)  
Unknown command: ‘import’  
Type ‘kolibri manage help’ for usage.  
root@tsp:/var/kolibri# kolibri status  
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base  
Stopped (1)  
root@tsp:/var/kolibri# kolibri start  
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base  
INFO Sqlite database Vacuum finished.  
INFO Running update routines for new version…

0 static files copied to ‘/root/.kolibri/static’, 767 unmodified.  
Operations to perform:  
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions  
Running migrations:  
No migrations to apply.  
Installed 2 object(s) from 1 fixture(s)  
INFO Running ‘kolibri start’ as daemon (system service)  
INFO Kolibri running on:

```
http://172.18.0.2:8080/
http://127.0.0.1:8080/

```

INFO Going to daemon mode, logging to /root/.kolibri/server.log  
root@tsp:/var/kolibri# kolibri status  
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base  
OK, running (0)  
Kolibri running on:

```
http://172.18.0.2:8080/
http://127.0.0.1:8080/

```

But this is the root user, and can’t remember if this was still an old image, therefore i’m starting over.

---

<div class="post-metadata">

**Author:** ![Bryan\_Fisher](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.learningequality.org/bryan_fisher/32/160_2.png) [@Bryan\_Fisher](https://community.learningequality.org/u/Bryan_Fisher)\
**Post date:** [November 9, 2018, 11:41am UTC](https://community.learningequality.org/t/manually-verify-import-content-on-database-file/894/8 "2018-11-09T11:41:14Z")

</div>

Hi @jredrejo,

After installing a fresh image, updating the system, Kolibri updated to v0.11.0 successfully.

Version: 0.11.0  
OS: Linux-4.4.0-138-generic-x86\_64-with-Ubuntu-16.04-xenial  
Installer: apt  
Server: Kolibri internal server  
Database: /var/kolibri/.kolibri/db.sqlite3  
Device name: tsp  
Free disk space: 915 GB  
Server time: Fri Nov 09 2018 13:35:48 GMT+0200 (South Africa Standard Time)  
Server timezone: Africa/Johannesburg

Thanks so much for your assistance in this matter. Much appreciate it.
