Restoring Nextcloud Tasks

A few months ago due to my own laziness we ended up losing my main ZFS storage array­. One of the things lost was my Nextcloud VM, which used a zvol as its main storage space. The files themselves were easily recoverable as we had full copies on three separate machines but we personally use Nextcloud Tasks, and as it turns out there’s no easy way to backup your data from the server itself.

Cue much banging head against keyboard. By sheer chance and an offhand reddit comment leading to a github comment we were able to find a workaround via DAVx and Tasks.org, the software we already were using to sync our calendar and tasks (CalDAV) to our android device.

The issue is that locally the app has a record of the object existing on the server, but when it queries the server the object is no longer there. This indicates that the object was deleted, so Tasks deletes the local copy.

When you restore from a backup you’re restoring the same task that thinks the object exists on the server. When it queries the server again the object is still missing, so the local copy gets deleted again.

What you can do is put your phone in airplane mode, load your backup file, then use long press + multi-select to move all of your data to local lists. Then you can turn off airplane mode, let it sync once (not sure if this is necessary), then move all of your data from the local lists back to the caldav server

edit: tasks doesn’t support exporting to ics, but this is something I would like to support in the future
abaker commented on Feb 16

This gave us a path forward in restoring five years worth of tasks, as we wanted to keep eveything including old archived tasks instead of having to start over. The process is somewhat involved.

DAVx

Disable synchronization for all involved accounts. In my case there were two CalDAV accounts, one for the failed NC server and another for the newly provisioned NC server. Then put your phone in airplane mode just to guarantee there is no communication between your device and the server.

If this gets messed up there is a fair chance everything is lost and we don’t want that, now do we.

Tasks.Org

  1.  ☰ → Settings → Backups → Backup Now. Make sure it’s a folder the OS can access without additional permissions. The default folder is hidden to all apps by default and the only way to get to it is connecting the device to a computer cos Google hates you.
  2.  ☰ , scroll down to the “Local lists”. Create as many lists as you need to restore to NC.
  3. Open the original task list, tap bottom-right ⋮ → Enable “Show completed”. If you don’t do this you’ll only be backing current uncompleted tasks!
  4. Tap upper-right ⋮ → Select all
  5. Tap the list icon List glyph, tap the local list you want to move all of these tasks to.
  6. Repeat steps 3, 4, and 5, for as many lists as you have.

At this point all of your tasks live on your device. Strongly recommend creating another tasks.org backup and immediately copying it to another device just in case your device dies. If you have pets you know how quickly this can happen.

Nextcloud

Create lists to match the local lists on your device (if they haven’t been created already)

DAVx

Disable airplane mode and delete the account for the failed NC server. If you have not added the account for the new NC server, you can do so now (or enable sync for it at this point)

Tasks.Org

Before proceeding, make sure the lists from the new NC server show up in the list manager and your backup is copied off device. Now we basically do the reverse of earlier

  1. ☰ , scroll down to the “Local lists”.
  2. Open the a local task list, tap bottom-right ⋮ → Enable “Show completed” (if it isn’t already).
  3. Tap upper-right ⋮ → Select all
  4. Tap the list icon , tap the NC list you want to move all of these tasks to.
  5. Repeat steps 3, 4, 5 as required.
  6. ☰ → Settings → Backups → Backup Now.

This backup will contain the tasks as connected to the NC account with its lists and should start synchronizing up to Nextcloud. You can also sync manually in DAVx.

We hope this helps someone in the future other than myself, cos it certainly was a total pain in the ass. We originally tried messing with the raw JSON making up the CalDAV objects but due to the way the protocol works going this route failed. Both Nextcloud and tasks.org have exporting data to ICS on the roadmap but it’ll take a while to get implemented.

Better yet, make sure you have replacement hardware for whatever hardware fails, and attend to those failures promptly.