34

I save my configuration in a Git repository to restore it easily later.

Recently, I stumbled upon an issue where needed to change GNOME settings with the gsettings command.

Is there a way to save these settings in a file that could be symlinked or copied in a predefined location expected by GNOME? I would prefer a method where I don't need to write a script to call gsettings.

muru
  • 197,895
  • 55
  • 485
  • 740

3 Answers3

29

Here a little correction for "Dobey" commands :

It's ok to save all donf settings like this :

dconf dump / > dconf-settings.ini

But you have to restore them like that ! :

dconf load / < dconf-settings.ini
jokx
  • 291
25

GNOME settings are generally stored via the GSettings API, which is an implementation of the DConf specification. This stores the settings in a binary database, which should not be replaced while logged in.

Instead, the settings need to be exported and then loaded in again.

You can use dconf dump / > dconf-settings.ini to dump the settings to an INI file, and then use cat dconf-settings.ini | dconf load / to load those settings back in. You can replace the / with a specific path to limit what settings are dumped and loaded. See man dconf for more details there.

If you want to simply set a single key, rather than whole paths, it would be better to use gsettings for this, with gsettings get and gsettings set in a script.

mivk
  • 5,312
dobey
  • 40,982
  • This mean the whole dconf configuration will be saved and restored, right? I would like to save just what I need actually. Can I dconf load the part I'm just interested in? – Morgan Courbet Dec 08 '17 at 08:47
  • @MorganCourbet that would be dconf read and dconf write, but gsettings is a more convenient for that, IMO – muru Dec 08 '17 at 08:57
  • @MorganCourbet You can limit to specific paths (groups of settings, such as all the settings for a specific app) with dconf, but for specific individual settings it would be better to simply use the gsettings get/set commands. – dobey Dec 08 '17 at 12:57
  • useless cat: dconf load / < dconf-settings.ini or < dconf-settings.ini dconf load – Anders Mar 28 '22 at 22:06
4

See man 7 dconf:

KEY FILES
   To facilitate system configuration with a text editor, dconf can
   populate databases from plain text keyfiles. For any given system
   database, keyfiles can be placed into the /etc/dconf/db/database.d/
   directory. The keyfiles contain groups of settings as follows:

       # Some useful default settings for our site

       [system/proxy/http]
       host='172.16.0.1'
       enabled=true

       [org/gnome/desktop/background]
       picture-uri='file:///usr/local/rupert-corp/company-wallpaper.jpeg'

   After changing keyfiles, the database needs to be updated with the
   dconf(1) tool.

If you just need to have GNOME pick up settings from a file without scripting, this might be the simplest way, but it needs administrator access for creating the key file.

The other option is to save the binary dconf database itself, but that's not a good option for use with Git as version control. The database is typically located in $XDG_CONFIG_HOME/dconf (i.e., ~/.config/dconf by default). See section on PROFILES in the manpage.

The manpage also says:

   The binary database format that dconf uses by default is not suitable
   for use on NFS, where mmap does not work well. To handle this common
   use case, dconf can be configured to place its binary database in
   XDG_RUNTIME_DIR (which is guaranteed to be local, but non-persistent)
   and synchronize it with a plain text keyfile in the users home
   directory.

But it's not exactly clear how to do this without scripting.

muru
  • 197,895
  • 55
  • 485
  • 740
  • Oh OK I just learned dconf was related to gsettings. Indeed, if the database is binary, I will not choose this method to keep track of it on Git. I think the first method is pretty much what I'm looking for. I'll try that out as soon as I can. After changing keyfiles, the database needs to be updated with the dconf(1) tool Does this mean I need to run dconf with some parameters to make my changes taken in account? – Morgan Courbet Dec 08 '17 at 08:43
  • @MorganCourbet Yes, dconf compile, see, for example: https://askubuntu.com/a/875922/158442 It needs to be done only once, though. – muru Dec 08 '17 at 08:58
  • 1
    The files in /etc/dconf are for affecting settings system-wide though, and not great for storing a user's settings in git. It might be OK for a single-user machine, but will affect the login screen and guest sessions as well. I would not recommend this method. Storing the binary db in git is not recommend either, as it is a good way to lose data. A minor bit of scripting is necessary here. – dobey Dec 08 '17 at 13:03
  • @dobey given the OP's case (touchpad settings, indicating a personal laptop) affecting the lock and login screens would be a bonus :) – muru Dec 08 '17 at 13:07