Scripts for backing up and restoring the MATE Panels

More than once, I wanted to remove a launcher from a MATE panel, but inadvertantly deleted the entire panel! This may easily happen.

There is the MATE Tweak Tool which helps with this. Under ‘Panel’ > ‘Panels’ you can save (and restore) your current panels’ layout. Possible problem: when the menu-button is lost with the deleted panel, the average user may struggle a bit to get the menu-button back on the remaining panel in order to launch the MATE Tweak Tool and restore his/her panels.

Before I realized the same can be achieved with MATE Tweaks, I wrote two simple scripts for backing up and restoring the MATE panels. Theses scripts backup and restore the entire dconf settings and configuration, not only the panels. This may be useful in some situations. The scripts may be put in the $HOME folder in case of an “emergency”:

1. Backing up MATE Panels

#!/bin/bash

# This is to trigger possible re-sorting of launchers on the panels before saving the new state
nohup mate-panel --replace > /dev/null 2> /dev/null &

echo ""
echo "Backup your panels:"
echo ""
echo "|| Check: Are the launcher icons correct in your panels ? ||"
echo ""
read -s -n 1 -p "Backup .config/dconf file 'user' ?  J/N  >" answer

echo ""
echo ""

if [ "$answer" == "j" -o "$answer" == "J" ]; then

	timestamp=`date +"%Y-%m-%d--%H.%M.%S"`

	echo ""

	# This backs up your current panels
	cd ~/.config/dconf

	## if empty, errors are sent to null device with 2> /dev/null
	ls -A1t  user.backup.* | tail -n +11 | xargs rm 2> /dev/null
	cp user.backup  user.backup.${timestamp}
	rm user.backup
	cp user         user.backup

	echo ""
	echo ""
	echo ".config file 'user' has been backuped."
	echo ""
	echo ""
	read -s -n 1 -p "Press ENTER >"
	echo ""
	echo ""
fi

2. Restore MATE Panels

#!/bin/bash
echo ""
read -s -n 1 -p "Restore your panels (please, close all programs before !) ?  J/N  >" answer

echo ""
echo ""

if [ "$answer" == "j" -o "$answer" == "J" ]; then

	killall -9 mate-session

	# This restores your panels
	cd ~/.config/dconf
	cp user.bak user

	sleep 1

	exit

fi