Backup your foldercolors

If you, like me, use foldercolors on external media, you might lose those foldercolors if you connect your drive to another Ubuntu-MATE computer (or after a complete new install)

Foldercolors are not saved on your external drive but in a binary format in a file in the folder $HOME/.local/share/gvfs-metadata
They are not stored on the external drive

To save my foldercolors (in a human readable form) to my external drive (and restore them when needed), I have two scripts: One to backup the foldercolors and one to restore them.

backup_folder_colors

#!/bin/bash

attribute="metadata::custom-icon"

find . -type d | sed 's|\(^.*\)/.*$|\1|' | sort | uniq | while read folder
do
	gio list --attributes=${attribute} ${folder} 2>/dev/null | sed "s|^|${folder}/|"
done | grep ${attribute} | sed "s|${attribute}=||g" | cut -f1,4 | sort >folder_colors

Save this script in the root of your external drive and make it executable
Run it from the root of your external drive.

You will discover that it may take a minute (or a few) to scan the disk.
Afterwards you will end up with a file folder_colors which contain the folder color info in a tab separated format (and human readable)

Don't forget to run it after you changed colors or at least before you migrate your disk to another computer (or install)

restore_folder_colors

#!/bin/bash

while IFS=$'\t' read name icon 
do
	gio set "$name" "metadata::custom-icon" "$icon"
done <folder_colors

Save this script in the root of your external drive and make it executable.
Run it from the root of your external drive.

But why not copy the gvfs-file? :
Yes , you could copy the binary gvfs-file but since that file is only for gvfs' internal use, it is not guaranteed that its format is not susceptible to change, that's why i use the matching gio tool. The human readable form is also a bit easier to adapt in case of format changes or even changing to a system that has a completely different format.

5 Likes

I had no idea about the gio tool, very interesting. I wonder if this could be automated on umount of the external drive.