i think it would be worthwhile for borg to support reading config files. as the create commandline options get more and more complicated, the shell pipeline grows and grows. it is unlikely to hit the ARG_MAX limit (around 2MB on my system) but still, it seems a little counter-intuitive to have very long command lines like this.
i feel it would help in sharing scripts and best practices to allow borg to use config files. we could ship sample configs for home directories, full system backups, etc.
i would personnally use it for different backup targets: onsite, offsite, and different purge frequencies and so on.
when developping bup-cron, i fixed this by sucking in the config file through the commandline parser, simply. this means that:
borg create --stats foo::bar baz
becomes the config file:
repository=foo::bar
path=baz
Right now i use the following shell wrapper to call borg:
#! /bin/sh -e
# this script should not exist. there should instead be a borg cron
# subcommand that reads a freakin config file.
#
# that would need to be implemented in borg/archiver.py, with a hook
# in run() and a def do_cron() that would call do_create() and others.
# features missing from bup-cron:
# snapshots
# parity
# syslog
# timing
REPOSITORY=/media/anarcat/BOOK/borg
# check for more recent bup in /usr/local/
PATH=$PATH:/usr/local/bin
# custom tag for manual backups
tag=$1
# this is how you bootstrap the repo
# borg init $REPOSITORY # todo: -e keyfile?
if [ ! -d $REPOSITORY ]; then
mail -s "backups failed" root <<EOF
$REPOSITORY not mounted, nightly backups failed
you're own you're own buddy.
email fired from $0
EOF
else
borg create --do-not-cross-mountpoints \
--stats \
$REPOSITORY::$(hostname)-$(date +%Y-%m-%d)$tag \
/ /boot /usr /var /home \
--exclude-caches \
--exclude "/home/*/.cache" \
--exclude "*/.Trash-*" \
--exclude "*/[Cc]ache/*" \
--exclude "*/.bitcoin/blocks/*" \
--exclude "*.vmdk" \
--exclude "/tmp/*" \
--exclude "*/build-area/*" \
--exclude "/proc/*" \
--exclude "/dev/*" \
--exclude "/sys/*" \
--exclude "/var/cache/*" \
--exclude "/var/tmp/*" \
--exclude "/var/log/*"
fi
as the comments describe, i was considering implementing this as a bup cron command that would be designed to run under cron. it could also purge old backups - so it would combine create and purge in one single pass.
the way i did this is with fromfile_prefix_chars (i used fromfile_prefix_chars='@') and then inspect files in standard locations (by injecting @foo.conf in the commandline at startup). the config files checked were /etc/bup-cron.conf, ~/.bup-cron.conf and ~/.config/bup-cron.conf.
Config file locations could be:
/etc/borg.conf~/.config/borg.conf~/.borg/configOr maybe we could define multiple "jobs" that would simply be ran in sequence in directories:
/etc/borg/<jobs>.conf~/.config/borg/<jobs>.conf... etc.
and yes, i know about atticmattic but it seems overkill and duplication of code to have a separate software to handle what is basically a fundamental aspect of borg, which is configuration of behaviour...
potential duplication of code (or implementation of features I don't need) in other projects is nothing I care much about.
but integrating stuff into borg that is usually located outside of it and adding config file parsing would cause a lot duplication and additional work here. if you add or change a feature, you currently have to edit 1 place (argparse related code). With additional config file, you would have to change 2 places.
also, if you think what would be needed to integrate everybody's backup related scripting needs into borg + configfile, you'ld be just reinventing shell scripting and atticmatic and what else and integrate everything into borg. this would just lead to an endless stream of feature requests until everybody's need are integrated (which would otherwise be a non-issue because people would just write a script as needed).
so, in short, I am still rejecting this as out of scope and even harmful.
if you add or change a feature, you currently have to edit 1 place (argparse related code). With additional config file, you would have to change 2 places.
no... the way i suggest this be implemented does _not_ require additional changes when new options are introduced. the options in the config file would be the same as on the command line and you'd still only have to change the argparse builder when you introduce new options. that's the whole point of fromfile_prefix_chars.
and people can still write their own shell scripts as well, of course. enabling config files doesn't force people to use them.
so if it is the same in the config file as on the commandline, what's the point?
the point is that non-technical users don't need to learn the shell and they can copy-paste examples from others more easily. having a config file enables shared configs more easily, in my opinion, as instead of running arbitrary codes from strangers, you have a limited set of things the config can do, controlled by borg.
it would also allow one command to both purge and create.
i wouldn't want people to run random shell scripts as root, as a general practice. copy-pasting configs seems like a better idea.
OK, I agree on creating a 1:1 equivalence between commandline and config file (using the same "verbs") if it does not require maintaining code at 2 places.
I don't agree on adding any additional functionality to be triggered via the config file (like pre or post commands, like "scripting" multiple commands, doing mounts or snapshots, cron-like stuff or whatever).
Also, this is not for 0.28.
BTW, something much more needed than that (IMHO) is a config file for defaults (if one is not happy with the builtin ones).
how about just doing prune alongside create? can i get that in? :)
i agree that snapshots and mounts may be feature creep for now (although we have #225 for par2, for example)...
no. :) and if you look at the faster cache sync PR, you'll see one reason why.
when sharing a repo, if you prune often (and it really deletes an archive), you will have expensive full cache rebuilds often. thus, create should happen often and prune only now and then to get better performance most of the time.
i did look at it, but i am a little confused by that code and couldn't review it properly, so i don't understand the reference. :)
+1
There is (at least) one drop in replacement for argparse, called ConfigArgParse, that adds additional support for setting flags via env vars and config files. I would expect it to be properly maintained in the future since the _Let's Encrypt_ client depends on it. It has build-in support for defining default config files and user defined config files.
@qua-bla what does that give us over the builtin fromfile argument to argparse?
environment variables are interesting - but we are already using those completely separately - not sure about merging the two...
Only a few but imho important features @anarcat
default_config_files=['/etc/borgbackup/borgbackup.conf', '~/.config/borgbackup/borgbackup.conf'] which also enables to set system wide defaults as mentioned by @ThomasWaldmann--config option that also appears in the help output (instead of @ or other fromfile_prefix_chars)--option=)Not sure, but the support for environment variables might simplify to bash script around custom needs?
I have to admit that it there are few problems
exclude into a global config, I cannot run init without an error. Partially, config files for sub commands make sense (e.g. serve) and they are supported. However, I'm not sure if config files per sub command + maybe one overall config is sane.close/wontfix?
Some ideas maybe make sense, some other maybe do not.
I'ld have to actually see the code and its consequences.
Pulling in a dependency just for this doesn't seem feasible, especially since "ConfigArgParse" isn't widely packaged. If it's possible without extra dependency...
Just for reference: I hacked together a crude shell script for that purpose. It is pretty ugly right now, but thought I might share it anyway: https://github.com/dragetd/borg_auto
I've also created an similar Bash Script some months ago.
https://github.com/fti7/borgsphere
@dragetd @fti7 if you like, add the link to the community repo of us via a PR.
Just did something similar in Python (highly opinionated, for my personal use mainly): https://gitlab.com/lefeverd/borgwrapper
@lefeverd can you add description of your wrapper to https://github.com/borgbackup/community?
Most helpful comment
potential duplication of code (or implementation of features I don't need) in other projects is nothing I care much about.
but integrating stuff into borg that is usually located outside of it and adding config file parsing would cause a lot duplication and additional work here. if you add or change a feature, you currently have to edit 1 place (argparse related code). With additional config file, you would have to change 2 places.
also, if you think what would be needed to integrate everybody's backup related scripting needs into borg + configfile, you'ld be just reinventing shell scripting and atticmatic and what else and integrate everything into borg. this would just lead to an endless stream of feature requests until everybody's need are integrated (which would otherwise be a non-issue because people would just write a script as needed).
so, in short, I am still rejecting this as out of scope and even harmful.