-
-
Notifications
You must be signed in to change notification settings - Fork 743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
please add something like --existing-ok to init command #271
Comments
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. 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 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 ***@***.***> 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
<#271 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzVssUAmM0NxCxeejbjV77lshnVQKSYks5tkoVFgaJpZM4GNzoc>
.
|
|
I'm having the same issue, because my script runs borg for a subdirs set, and a new subdir may appear. I use
before every |
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 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 Would this be a solution? Or do you require exit code 0? |
@fantasya-pbem $ docker run -it --rm alpine sh
/ # apk add -q moreutils
/ # errno 1
EPERM 1 Operation not permitted Most shell scripts (should) have exit early flag, so the strategy for conditional checks is to bail on any statement that returns an exit code != 0. As others have suggested before me, i'd like to automate this behavior without having to worry whether the repository exists, because from a declarative perspective, my only concern is that it does exist, not whether it did or did not exist previously. |
Let me tell you my story: I'm using During the process, I adopted the exit status as indication by allowing
This worked well until I realized that a unsuccessful ssh connection to the borg master (e.g. because of a blocking network ACL or firewall) results in borg existing with the same known-to-be-good exit status of Back to quare one. I believe there is still need for a idempotent way to make sure the repo exists. |
2 just means something like "sudden, fatal error". 1 is some warning (needs manual log checking). 0 is success. |
Yep thanks for confirming. I realized back in 2015 you argued that Do you acknowledge the need for such a flag e.g. |
i still think this is complex, unclear and can have / cause lots of issues. so if somebody wants to put a lot of work into this, make a PR (after making a good plan considering all the potential cases) and I'll review it. |
We will have to figure out the exact goal, scope and behaviour of I imagine The feature is fully backward compatible as it does not change existing behavour. I'm eager to hear feedback on the proposal as well as your insight and consideration into the complexity and problems it may cause. |
I think the ideal for provisioning tools like ansible would be to have a command that ensures the path is a working Borg repository. But I guess this is simply not reasonably possible (i.e. without simply dropping the directory in case everything is not OK). The suggestion MEschenbacher detailed would IMO be practical to simplify normal situation handling through ansible and the like. However, I think the name should be clearer about the fact is does nothing if the directory exists and is not empty (it could be |
Can we please decide on a solution for this since it's a 6 year old issue that has some real valid use cases? |
We recently automated some borg stuff and I ran into issues with the The current ansible solution we use is like this:
|
Could a different error code be used for when the entire directory of the repo doesn't exist or would that complicate the code too much? |
@dami0 do you mean the parent directory of the repo directory? |
No, the actual directory of the repository itself, just to simplify the error handling so we can distinguish between the repository not existing and problems accessing like when the lock is present. |
@dami0 still working on improvements in #7976 ... From frontends.rst docs (the rc exit codes given will be used when "modern" exit codes are enabled):
So, guess this is enough for scripts to decide what to do if borg exits with one of these codes. Especially |
In borg 1.4-maint and master branches, I think this is the better solution than adding an option to ignore this and the return code can be checked in the wrapper and it can react accordingly, depending on whether that is expected or not (usually one runs |
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).
The text was updated successfully, but these errors were encountered: