Skip to content
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

bad file descriptor error #6222

Closed
awgcooper opened this issue Feb 2, 2022 · 2 comments
Closed

bad file descriptor error #6222

awgcooper opened this issue Feb 2, 2022 · 2 comments

Comments

@awgcooper
Copy link

Have you checked borgbackup docs, FAQ, and open Github issues?

Yes

Is this a BUG / ISSUE report or a QUESTION?

Question

System information. For client/server mode post info for both machines.

Client: WSL2, Debian 11, Windows 10 Pro
Server: Ubuntu 20.04.3

Your borg version (borg -V).

borg 1.1.17

Operating system (distribution) and version.

See above

Hardware / network configuration, and filesystems used.

How much data is handled by borg?

500GB

Full borg commandline that lead to the problem (leave away excludes and passwords)

borg create repo backupdir
borg list repo

Describe the problem you're observing.

I have a well tested script to automate the main borg functions I use. Repo location, backup dirs, keyfile, keyfile password are all managed either as bash variables or Borg envvars where applicable. I've never had any difficulties with this script.

I decided I wanted to replace the envvar BORG_PASSPHRASE with BORG_PASSPHRASE_FD and therefore implemented the following in my backup script:

  1. I have a read-only text file, 'conf_file', which has the keyfile passwords for the different repos I backup to. The format of the file is:
    [repo1]:[passwd1]
    [repo2]:[passwd2]
    etc
  2. my borg script takes the flag '-r' to designate the repo name which becomes the variable $repo_name. Therefore ./borgscript.sh -r repo1 --> repo_name="repo1"
  3. To extract the correct password from conf_file and write it to an FD I do the following:
    a) exec 37>file
    b) echo $(grep -o $repo_name'.*' conf_file | cut -f2- -d':') >&37 [this matches the repo name and returns the string after the delimiter ':' which is the password]
    c) export BORG_PASSPHRASE_FD=37
  4. These changes above replace the previous method which was export BORG_PASSPHRASE. Otherwise nothing has been change from the script which was working just fine.
  5. As a test, if don't use the script but rather manually create and populate the FD and then run 'cat 37' the console output is indeed the correct password for $repo_name.
  6. Furthermore, if I don't use the script at all but manually enter in all the variables necessary to run borg list repo first using the old method, export BORG_PASSPHRASE and then using export BORG_PASSPHRASE_FD=, the first method works, the second doesn't.

Can you reproduce the problem? If so, describe how. If not, describe troubleshooting steps you took before opening the issue.

Yes, manually entering the commands.

Include any warning/errors/backtraces from the system logs

Local Exception
Traceback (most recent call last):
File "borg/archiver.py", line 4703, in main
File "borg/archiver.py", line 4635, in run
File "borg/archiver.py", line 164, in wrapper
File "borg/helpers.py", line 382, in load
File "borg/crypto/key.py", line 134, in key_factory
File "borg/crypto/key.py", line 594, in detect
File "borg/crypto/key.py", line 438, in env_passphrase
File "borg/crypto/key.py", line 461, in fd_passphrase
OSError: [Errno 9] Bad file descriptor

Platform: Linux DESKTOP-31MLCGH 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64
Linux: debian 11.2
Borg: 1.1.17 Python: CPython 3.7.11 msgpack: 0.5.6.+borg1
PID: 2008 CWD: /proc/1384/fd
sys.argv: ['borg', 'list', '--remote-path=borg1', 'ssh://repo.borg']
SSH_ORIGINAL_COMMAND: None

@ThomasWaldmann
Copy link
Member

Looks like nobody could help here, but considering the age of this issue, I suspect some solution was found.

@awgcooper
Copy link
Author

Thanks for checking in. I can't quite remember the path I took but here's my working bash script implementation of the BORG_PASSPHRASE_FD envvar:

  1. get_passphrase function
  • lookup passphrase based on repo name ( stored in a local 0400 perms file)
  • passphrase saved to $pw
  1. transfer to file descriptor
  • using an arbitrary number fd: exec 5<<< "$pw"
  1. export the envvar
  • export BORG_PASSPHRASE_FD="5"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants