i think it would be pretty nice (and quite useful for my case) to have an option to make borg not fail with exception and traceback on 'borg init' when the repository already exists.
that way, i could set my backup script (which basically does init+create+prune) to exit on failure (set -e).
considering you need init only once (and it even needs to be interactive when using encryption), what's your use case precisely?
i understand the use case: just have a wrapper that creates the repo if missing, and not fail otherwise. it could check if the directory exist, but that's an extra step... borg could just avoid failing...
borg init is not automatic for every usecase. If you enable encryption, it will ask you for a passphrase.
there might be also a security question the first time one accesses a previously unknown repo.
Also, wouldn't you rather want to know if a repo that should be at some specific target location suddenly vanishes and needs to get recreated than just silently recreating it?
fair questions! (and i'm currently reworking my script) but still, borg - as a backup solution - should be as non-interactive friendly as possible (imho) to be made run easily from cron etc...
@rpodgorny agreed.
I still think init should be manual (as far as borg is concerned).
For the same reasons why you maybe do not want to automate fdisk/mkfs/labelling backup disk preparation steps.
Hi,
I'm updating an old issue with a wider request.
I'm working to a wrapper script as others and the interactive nature of borg can be a problem. What @rpodgorny speak about here is just one use case. Environment variables are a good "workaround" but not a "standard" way of think, even when using manually. Think about many command line tool which use switch, good example is "rm -f".
My "wrapper script" run borg remotely on many servers from one central server, some sort of scheduler. I rely on SSH and it's not so easy to pass environment variable (I need to add a helper script on all servers). Having command line switch would be easer ;).
But, my main problem is the interactive stuff. I would like borg to use the default answer when the environment variable is not set. Instead, it what for answer on stdin and this can block my script (workaround in progress). It would be very usefull to have some --non-interactive option at least.
Hi,
I was looking for a way to ensure some borg repository is initialized and ended up here. My goal is to have one central backup server with one borg repository for each server and manage everything with ansible (i.e. have both server and backup configuration automated).
The least dirty workaround I can think of would be to use borg check to check if the repository is created but this would likely end up in ansible runs taking up a long time :/ and the only realistic solution I could think of is to check that borg init fails with return code 2 and a message like "Repository .* already exists." in stderr…
Are there good reasons not to do what I try to do ? (I know having multiple repositories will use more disk space.)
Unless I don't understand your question, couldn't you just look at the
top-level of the directory for these contents:
README config data/ hints.1 index.1 integrity.1
michael at barrow dot me
+1.541.600.2027
"Do not anticipate trouble, or
worry about what may never happen.
Keep in the sunlight." -- B. Franklin
On Mon, Apr 2, 2018 at 1:08 PM, David-5-1 notifications@github.com wrote:
Hi,
I was looking for a way to ensure some borg repository is initialized and
ended up here. My goal is to have one central backup server with one borg
repository for each server and manage everything with ansible (i.e. have
both server and backup configuration automated).The least dirty workaround I can think of would be to use borg check to
check if the repository is created but this would likely end up in ansible
runs taking up a long time :/ and the only realistic solution I could think
of is to check that borg init fails with return code 2 and a message like
"Repository .* already exists." in stderr…Are there good reasons not to do what I try to do ? (I know having
multiple repositories will use more disk space.)—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/borgbackup/borg/issues/271#issuecomment-378029239,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABzVssUAmM0NxCxeejbjV77lshnVQKSYks5tkoVFgaJpZM4GNzoc
.
$ mkdir invalid
$ borg list invalid
/home/tw/invalid is not a valid repository. Check repo config.
$ echo $?
2
$ borg list doesntexist
Repository /home/tw/doesntexist does not exist.
$ echo $?
2
$ borg list repo
Enter passphrase for key /home/tw/repo:
arch Tue, 2018-03-27 00:58:06 [9db...c05]
...
$ echo $?
0
I'm having the same issue, because my script runs borg for a subdirs set, and a new subdir may appear.
I use
borg init --encryption=none $BACKUPS_DIR 2> /dev/null
before every borg create command.
I've written multiple wrapper systems for both attic + borg in multiple languages, and having to check if the repo exists and init only when it doesn't is the most complicated part. These scripts could be much simpler otherwise. Everyone else using scripts around borg, including all the Ansible configs etc have to write this logic and execute multiple commands for themselves too. It would be nice if it were just built in (and optional to use obviously).
I really wish there were a combined init+create command where I just put all the settings into a single command and borg will auto-init only if needed. It doesn't need to be the default behaviour or anything, but there are a lot of us who would use this.... basically anyone doing any automated setups with borg... which is quite a lot of us now.
So maybe rather than a new flag on the init command as suggested in this issue, it would be even simpler as a new flag --auto-init on the create command? Or perhaps instead even a new separate initcreate command to clearly separate it from the regular imperative init + create commands?
As for the 'needs to ask for passphrase' thing, that is already handled by either environment variables and/or using keyfile repos. Everybody that wants this feature is already scripting their own non-interactive inits.
For the people that don't want auto-init / want to know when the repo doesn't exist... obviously they just wouldn't use this feature. For me personally, I would use the feature on most of my repos, but not all them.
This feature would bring Borg more in line with more modern declarative over imperative practises of systems administration in general, and reduce a lot of the redundant (and bug prone) scripting that users of borg need to do for themselves for this fairly common use case.
Current behaviour of borg init is to exit with code 2 if repository does exist. Think of a new option like --warn-if-exists that makes Borg exit with code 1 if repo does exist (instead of error code 2).
Would this be a solution? Or do you require exit code 0?
Most helpful comment
Hi,
I was looking for a way to ensure some borg repository is initialized and ended up here. My goal is to have one central backup server with one borg repository for each server and manage everything with ansible (i.e. have both server and backup configuration automated).
The least dirty workaround I can think of would be to use
borg checkto check if the repository is created but this would likely end up in ansible runs taking up a long time :/ and the only realistic solution I could think of is to check that borg init fails with return code 2 and a message like "Repository .* already exists." in stderr…Are there good reasons not to do what I try to do ? (I know having multiple repositories will use more disk space.)