20

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.

2
  • 1
    What version of ubuntu ?
    – Panther
    Dec 7 '17 at 20:53
  • 1
    I'm using 17.10 with gnome shell Dec 7 '17 at 20:58
19

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.

3
  • 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? Dec 8 '17 at 8:47
  • @MorganCourbet that would be dconf read and dconf write, but gsettings is a more convenient for that, IMO
    – muru
    Dec 8 '17 at 8: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 8 '17 at 12:57
15

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
3

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.

4
  • 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? Dec 8 '17 at 8:43
  • @MorganCourbet Yes, dconf compile, see, for example: askubuntu.com/a/875922/158442 It needs to be done only once, though.
    – muru
    Dec 8 '17 at 8: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 8 '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 8 '17 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.