imap-backup
imap-backup copied to clipboard
Use XDG_CONFIG_HOME for config location
Instead of hard coding a location, use the XDG spec for the config file.
This could be using something like: https://www.alchemists.io/projects/xdg/
Hi @cmol Using the XDG spec makes a lot of sense. Any PR that implements this would be welcome.
Reopening this in the hope of attracting comment on the following:
Why?
The advantage of adopting the XDG spec is that imap-backup would not "pollute" the user's home directory with it's .imap-backup directory.
Is XDG Relevant to imap-backup?
XDG stands for "X Desktop Group", which is the former name of freedesktop.org. The specs they produce relate to desktop systems.
imap-backup, on the other hand, is meant principally for headless machines - systems that stay on all the time where it makes sense to run cron jobs.
How Would it Work?
The default location of the configuration would become ~/.config/imap-backup/config.json.
The problem is where to store the backups.
Storing them under ~/.config/imap-backup makes no sense – they hold data, not config.
On a desktop system, XDG_DOWNLOAD_DIR seems the best candidate, but this environment variable, and the default directory – $HOME/Downloads – don't exist on non-desktop systems.
On a non-desktop system, the most logical path would seem to be under /var.
a. all installations could default to storing backups under $HOME/Downloads/imap-backup, which it would be fine for desktop users, but for other systems, would make no sense,
b. using different storage locations for desktops and non-desktops would get confusing for users,
c. creating a new directory would take us back to the problem we started from.
The default location of the configuration would become ~/.config/imap-backup/config.json.
Seems sensible to me.
It would be great to be able to point to a custom config location via an option:
$ imap-backup --config=/path/to/config.json
The problem is where to store the backups.
I've just picked this tool up, and I was kinda surprised that the backups weren't created in the current working directory.
$ imap-backup
# Backs up to current directory
$ imap-backup --path=/var/imap/[email protected]
# Backs up to /var/imap/[email protected]
For users running via a scheduler (cron/systemd/LaunchAgent/etc), I'd expect to add a path key in config.json
A little more about my use case. I've just picked this up after having used gmvault a few years back. I think that's basically a dead project now, and this is Ruby, so yay.
I use HashiCorp's Nomad to run various services on a home server. I mount a data directory from my NAS via NFS. I created a simple Dockerfile, and I was expecting to be able to mount the NFS share to /data within the container so that both the configuration and backups persist across container runs.
FROM ruby:3.0
RUN gem install imap-backup
VOLUME /data
WORKDIR /data
ENTRYPOINT ["imap-backup"]
At the moment this doesn't really work because imap-backup is defaulting to putting everything in /root. I guess I can probably create a new user with their home dir set to /data – I haven't explored that yet – but with the above options all this would have been as easy as – I think – changing the ENTRYPOINT:
- ENTRYPOINT ["imap-backup"]
+ ENTRYPOINT ["imap-backup", "--config=/data/config.json", "--path=/data/imap"]
I've just released imap-backup version 8.0.0.rc1. It has configurable location for the configuration file, via the --config PATH parameter.