How do I repair a corrupt database?

2Do uses the industry standard, SQLite embedded database to store your data. SQLite is lightweight, fast and can perform automatic recovery of failed or incomplete transactions under normal circumstances. In the rare event of a power-failure, sudden reboot or some other hardware related failure whilst in the middle of performing background sync, there is a slim chance of the database becoming corrupt, such that automatic recovery is no longer possible. This is more likely to occur on a Desktop / Laptop rather than an iPhone / Tablet. For phones and tablets, the easiest method of recovery, provided you have synced your data to the cloud, is to Reset your database from Settings > Advanced and setup sync to recover directly from the cloud.

Signs of a corrupt database are usually: search not working, sync not working or tasks not saving / deleting properly. Recovering from database failure is straightforward, albeit a manual process. The following instructions will help you self-diagnose a corrupt database and help you recover and repair your valued data. It should be noted here that 2Do creates automatic backups on a timely fashion (accessible from inside Preferences > Backups) for safe-keeping, however the following steps are there to help in case there isn’t a more recent backup to recover from.

  1. Spotlight for Terminal.app and launch it on your Mac
  2. Navigate to the db storage location by entering: cd ~/Library/Group\ Containers/EKT6323JY3.com.guidedways/
  3. Enter the following command and hit return: sqlite3 2do.db

The prompt should now display sqlite> to indicate you’re in the SQLite shell. To verify that you’re truly suffering from database corruption, enter the following command into the shell:

sqlite> PRAGMA integrity_check;

If the response is anything other than ok, the database is integrity checks have failed and needs to be repaired.

We need to now dump the data into an external file and re-create the database manually. Simply enter the following commands into the SQLite shell:

  1. sqlite> .mode insert
  2. sqlite> .output dump_all.sql
  3. sqlite> .dump
  4. sqlite> .exit

Now that we have the dump, let’s import it. You should now be out of the SQLite shell and back to the Terminal prompt. Execute the following statements:

  1. mv 2do.db 2do.orig.db
  2. sqlite3 2do.db < dump_all.sql
  3. sqlite3 2do.db

The first line above will move the original database out of the way. The second line will create a new one in place, using the dump we just exported. The last line should take us back into the SQLite shell in order to check if everything’s okay. Run the integrity check one more time and we should see OK as the response this time:

sqlite3> PRAGMA integrity_check;

That’s it, you’re done repairing the database. Re-launch 2Do to get back to getting things done.
Attached Files
There are no attachments for this article.
Related Articles
Which custom CalDAV servers are currently supported by 2Do?
Viewed 9,123.00 times since Tue, Nov 27, 2012
Does 2Do support printing tasks?
Viewed 4,161.00 times since Tue, Mar 31, 2015
When I enter a due / start date for December or March manually, it ends up showing the wrong date
Viewed 2,836.00 times since Thu, Nov 29, 2012
Preferences and settings don’t seem to stick, they reset when I relaunch the app
Viewed 2,320.00 times since Tue, Mar 31, 2015
Can the Focus Filter be configured differently for each individual list?
Viewed 4,616.00 times since Tue, Dec 4, 2012