# Trigger AnkiWeb sync from Linux command line

**URL:** <https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708>\
**Category:** Help\
**Created:** [May 26, 2025, 4:09pm UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708 "2025-05-26T16:09:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mk71645511](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mk71645511](https://forums.ankiweb.net/u/mk71645511)\
**Post date:** [May 26, 2025, 4:09pm UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/1 "2025-05-26T16:09:20Z")

</div>

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:

```auto
> 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.

---

<div class="post-metadata">

**Author:** ![sorata](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/sorata/32/34115_2.png) [@sorata](https://forums.ankiweb.net/u/sorata)\
**Post date:** [May 26, 2025, 4:20pm UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/2 "2025-05-26T16:20:35Z")

</div>

This:

> [@Automatic deck backups (export) from the command line (Linux)](https://forums.ankiweb.net/t/automatic-deck-backups-export-from-the-command-line-linux/7267):
>
> I want to export all of the decks of my user, and store them safely as an offline backup. I want to run it from a script periodically (probably through a cronjob), instead of having to manually export the decks from the Anki desktop interface (thus it has to run in the command line, preferably without Anki running). Are there any good tools to achieve that? From what I’ve seen, all the API interfaces for Anki focus on flashcard creation or other functionalities I have no interest in, and none se…

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

---

<div class="post-metadata">

**Author:** ![Anon\_0000](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Anon\_0000](https://forums.ankiweb.net/u/Anon_0000)\
**Post date:** [May 26, 2025, 4:35pm UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/3 "2025-05-26T16:35:20Z")

</div>

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](https://docs.flatpak.org/en/latest/flatpak-command-reference.html#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.

---

<div class="post-metadata">

**Author:** ![mk71645511](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mk71645511](https://forums.ankiweb.net/u/mk71645511)\
**Post date:** [May 26, 2025, 6:07pm UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/4 "2025-05-26T18:07:45Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Anon\_0000](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Anon\_0000](https://forums.ankiweb.net/u/Anon_0000)\
**Post date:** [May 26, 2025, 6:18pm UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/5 "2025-05-26T18:18:45Z")

</div>

> [@mk71645511](#):
>
> 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”?

Not that I know of, no.

> [@mk71645511](#):
>
> Or something similar with curl to `ankiweb.org` and an API key…

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.

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [June 2, 2025, 7:34am UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/6 "2025-06-02T07:34:07Z")

</div>

> **[Command-Line Use - Writing Anki Add-ons](https://addon-docs.ankiweb.net/command-line-use.html)**

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

---

<div class="post-metadata">

**Author:** ![mk71645511](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mk71645511](https://forums.ankiweb.net/u/mk71645511)\
**Post date:** [June 2, 2025, 1:03pm UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/7 "2025-06-02T13:03:11Z")

</div>

Of course 🙂

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`

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [June 4, 2025, 10:05am UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/8 "2025-06-04T10:05:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [July 4, 2025, 10:05am UTC](https://forums.ankiweb.net/t/trigger-ankiweb-sync-from-linux-command-line/61708/9 "2025-07-04T10:05:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
