As I’ve written before, I lock my games into an encrypted tomb to keep me from playing them when I should be working. Much harder than managing where games are installed, though, is managing where they store their saves.
Using Lutris and the magic of environment variables, I’ve found a solution to story all of my game saves in a single parent folder.
my game collection
To preface things, I should be clear that I’m incredibly selective about what games I play: I only play Linux-native games that are DRM-free. Usually, these are purchased through GOG.
Lutris has come into my setup lately as a very handy centralized program to launch my games from. There are a few niceties it brings to the table:
- one-click installation directly from GOG
- tracking play time
- ability to sync play time statistics across devices
And I certainly enjoy these features. But more critically for me has been all its features to help me get my games running properly. It’s better at managing the libraries needed, and several older 32-bit games I was finding impossible to run properly now work perfectly through Lutris. If I ever decide to try and play a Windows-only game, Lutris can also manage that automatically for me through Wine.
the problem
Now, despite making it easy to install all of my games in a single folder that I can lock at will via tomb, each game makes its own choice about where to save info about my progress. Usually, this is in a sub-folder of ~/.local/share, but sometimes it’s in ~/.config or even a folder in my home directory, which drives me nuts.
There are two big problems with this:
- It’s hard to lock these saves up as well; tomb can automatically mount things where they need to be, but I needed to set it up that way for each game
- It’s getting random files all over my lovingly-curated filesystem!
Clearly, something had to be done.
the solution
Last night, I began to wonder if I could trick games into saving things somewhere else, thinking they were saving where they intended. My first thought was to use chroot to fake a different filesystem, but that quickly got complex and insecure, as it would’ve required administrator permissions to my device to run games.
I quickly redirected my attention to environment variables. To those not in the know, these are essentially ways that my operating system can set certain pieces of information to tell things to programs. There are three that are most important for this article:
$HOME- this sets your “home” folder, which contains all your user files. Typically, this is at/home/<username>(for me,/home/amin) which can be written as~for short.$XDG_CONFIG_HOME- this sets the folder to contain your configuration files. This isn’t where most games store their saves, but some do. Typically, this is set to$HOME/.config.$XDG_DATA_HOME- a folder where programs (and, in this case, games) are asked to store data. This is where most games I own store their saves.
Now, Lutris has a very cool feature: you can tell it to set a different environment variable for a specific game when you run it, without affecting the rest of your system. Better yet, I can set default environment variables to use for all games so I don’t have to do this again each time.
The folder I want games to store their saves in is /media/games/data. Here are the environment variables I set:
HOME=/media/games/data
XDG_CONFIG_HOME=/media/games/data/.config
XDG_DATA_HOME=/media/games/data
This takes care of every game I own, nice and neat. Games that want to store in the configuration folder will put their saves in the .config subdirectory I made, games that assumed the configuration folder is $HOME/.config without checking will still use the right place, games using ~/.local/share will instead use the main data folder, and anything (ugh) storing directly in $HOME will also be redirected to that same data folder.
It’s flawless. I had to go around and move all my games’ existing saves to their new home, but all games I install going forward will automatically use this folder.
For those who’ve forgotten, why do this?
- to clean up my filesystem
- to be able to lock away that one folder to lock access to my saves when I need to work
- I could, in the future, store my games and saves on an external hard drive or flash drive (probably a use case you lovely readers will more likely have)
- and, the one I haven’t mentioned yet: backups!
the bonus: backups
I am a huge advocate of robust backup systems. All my important files are backed up hourly to an external hard drive (when I’m at my desk) and one to two remote locations.
However, telling my system to just back up everything takes up a lot of space with data I don’t care about (like the games themselves, which I can easily reinstall with the installers, which I back up). And with every game storing its save in a different place, it’s hard to tell my system where to look.
Worse, some were in my tomb and some weren’t, so it would look like the saves in the tomb had been deleted any time I didn’t have it unlocked.
Now that all my saves are in the same folder, backing them up is easy! I use borgmatic for my backups, so I set up a new Borg repository on my server and made a configuration file for my game saves.
source_directories:
- /media/games/data
- /media/games/controller-profiles
- /media/games/bind-hooks
- /media/games/desktop-files
- ~/.local/share/lutris
This gets all the important information I’ll want to keep and easily drop into place if I ever have to restore my game saves. /media/games/data is the folder with the game saves, but you can also see a folder with custom game controller profiles, desktop files to easily launch games, a file listing paths for tomb to mount when I unlock the tomb, and the data folder containing my Lutris library. (I have another line excluding the runtime subdirectory, which I don’t need to back up and is huge.)
But there’s one more important piece:
before_actions:
- findmnt "/media/games" > /dev/null || exit 75
This clause tells borgmatic to check before running a backup whether /media/games is mounted on my system; if it isn’t, the tomb with my games isn’t open and I can safely skip the backup (this will also help avoid making it look like all my saves have been deleted in some backups). This could also be useful if you want to store your games and saves on an external hard drive.
Incidentally, the backup of all my game saves and listings is only 10MB after borg compresses and deduplicates it.
conclusion
I am so excited about this setup, it feels much better than letting games save files wherever they want. And, as a bonus, it won’t require any additional work for future games to start using the system.
If you’ve got ideas about how to improve this further, stories to share about your own setup, or questions about how to do this yourself, feel free to contact me! My email address is below, and receiving emails about my posts always brightens my day.