How to save GNOME settings in a file?
Solution 1
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.
Solution 2
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
Solution 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.
Related videos on Youtube
AbuuJurayj Swabur Buruhan
Software crafter, open source junkie, technology enthusiast, self-learner, skeptic, reasonable ecologist, video gamer, traveler, belgian beer lover
Updated on September 18, 2022Comments
-
AbuuJurayj Swabur Buruhan over 1 year
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
.-
Panther over 6 yearsWhat version of ubuntu ?
-
AbuuJurayj Swabur Buruhan over 6 yearsI'm using 17.10 with gnome shell
-
-
AbuuJurayj Swabur Buruhan over 6 yearsOh OK I just learned
dconf
was related togsettings
. 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 rundconf
with some parameters to make my changes taken in account? -
AbuuJurayj Swabur Buruhan over 6 yearsThis mean the whole
dconf
configuration will be saved and restored, right? I would like to save just what I need actually. Can Idconf load
the part I'm just interested in? -
muru over 6 years@MorganCourbet that would be
dconf read
anddconf write
, butgsettings
is a more convenient for that, IMO -
muru over 6 years@MorganCourbet Yes,
dconf compile
, see, for example: askubuntu.com/a/875922/158442 It needs to be done only once, though. -
dobey over 6 years@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 over 6 yearsThe 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. -
muru over 6 years@dobey given the OP's case (touchpad settings, indicating a personal laptop) affecting the lock and login screens would be a bonus :)
-
Anders about 2 yearsuseless cat:
dconf load / < dconf-settings.ini
or< dconf-settings.ini dconf load