Dotfiles backup and restore
2017-08-07For some time, I’ve wanted a backup of my dotfiles, just in case.
Backing up configuration files
I could keep a Git repository, but currently, a simple folder on my laptop, for which I have complete backups via restic
, is good enough for me. I rarely change dotfiles, I prefer using tools that do the heavy lifting for me without too much configuration.
Restoring our configuration
Whenever I need to restore dotfiles, I have this little script that will make symlinks as needed:
#!/bin/bash
set -euo pipefail
cd dotfiles
for f in `find . -type f | sed 's#^./##'`; do
# create the directory in which to put the config file's symlink
echo -n mkdir $HOME/`dirname $f`
read
mkdir -p $HOME/`dirname $f`
# create the symlink
echo -n ln -sf $HOME/dotfiles/$f $HOME/$f
read
ln -sf $HOME/dotfiles/$f $HOME/$f
done
cd ..
It shows me what it is about to do, asks for confirmation and then creates the symlink where it should be. For instance, ~/dotfiles/.bashrc
gets symlinked to ~/.bashrc
. Then, when Bash looks for its configuration, it will to ~/.bashrc
which will point to ~/dotfiles/.bashrc
.