Trigger AnkiWeb sync from Linux command line

I use AnkiWeb to sync my decks across various devices. I want to set up an additional cron job from a Linux machine to back up my data from AnkiWeb to a local file for safekeeping.

I read here on this forum[1] that it suffices to back up the Anki data directory, which on my workstation (where I have installed Anki as a flatpak) is ~/.var/app/net.ankiweb.Anki/data/Anki2. Great!

Except one problem … I actually almost never open the Anki desktop app, and do all my studying on mobile. The main reason I have Anki installed is so that my desktop has a way to talk to the AnkiWeb server and update itself so that I can run this backup.

So, my question is, is there a command I can run at the command line inside of a cron job that will trigger Anki to do a sync that I can issue prior to backing up the Anki data directory?

What I’ve tried

In a desktop session, running timeout 60 flatpak run net.ankiweb.Anki is enough—it loads up the full GUI, lets it sync automatically, then kills it.

But in my backup script, this fails with The application failed to start because no Qt platform plugin could be identified. I tried setting QT_QPA_PLATFORM=offscreen but this doesn’t work either:

> QT_QPA_PLATFORM=offscreen timeout 60 flatpak run net.ankiweb.Anki
Python module pip_system_certs is not installed. System certificate store and custom SSL certificates may not work. See: https://github.com/ankitects/anki/issues/3016
Starting Anki 25.02.4...
Qt warning: setHighDpiScaleFactorRoundingPolicy must be called before creating the QGuiApplication instance 
2025-05-26 11:04:25,688:INFO:aqt.mediasrv: Serving on http://127.0.0.1:46403
Qt warning: QRhiGles2: Failed to create temporary context 
Qt warning: QRhiGles2: Failed to create context 
Qt warning: This plugin does not support createPlatformVulkanInstance 
Qt warning: QVulkanInstance: Failed to initialize Vulkan 
Qt warning: Unable to detect GPU vendor. 
[2:21:0526/110425.878038:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
Starting main loop...
Qt warning: This plugin does not support propagateSizeHints() 
Qt warning: This plugin does not support raise() 
Qt warning: This plugin does not support propagateSizeHints() 
Qt warning: This plugin does not support propagateSizeHints() 
Qt warning: This plugin does not support propagateSizeHints() 
Qt warning: This plugin does not support propagateSizeHints() 
Qt warning: This plugin does not support propagateSizeHints()

  1. As a new user, I’m not allowed to post links, but if you search “Automatic deck backups (export) from the command line (Linux)” the relevant post will come up. Maybe a mod can edit a link in for me. ↩︎

This:

You could include a link inside a code block, by the way.

I never tried to run a flatpak from a cron job, but maybe the following could help you a bit?

  1. Maybe you need to setup QT_QPA_PLATFORM_PLUGIN_PATH, so that the app can find the plugins? It apparently often points to /var/lib/flatpak/app/<app-id>/current/active/files/lib/qt6/plugins/platform.
  2. Maybe flatpak-spawn can be used?
  3. Maybe compare the env output of your cron job and your regular user to find differences?
  4. Apparently some users could use cron if the flatpak was installed with --user (rather than --system) – though their issue was with using the flatpak update command.

Thank you! I’ll play with your suggestions, but I take this to mean that the correct way to approach this is definitely to try to get the full client to run offscreen? I.e. there’s no flag I can issue at the command line to say “Don’t load the GUI, just sync decks and exit”? Or something similar with curl to ankiweb.org and an API key…

Not that I know of, no.

At least not officially, as far as I know.


  • Maybe there’s some way with python (as a script) – but I’m not knowledgable enough to know for sure.
  • Or maybe an addon could be written (uses python too), that automatically triggers a sync on startup, then auto exports your decks, then closes anki.

If you automate syncing, please do it infrequently to avoid server impact.

3 Likes

Of course :slight_smile:

Would you be able to link me to a more specific section of the API docs? The part you linked assumes a local .anki2 database and doesn’t say anything about how to retrieve/sync this from the server.

I found this page about the database but it again seems to assume a local database and doesn’t say anything about authenticating to ankiweb:

https://addon-docs.ankiweb.net/the-anki-module.html#the-database

You’ll need to read the source and/or generate the API docs with something like uvx --install anki python -m pydoc anki.collection