vorta icon indicating copy to clipboard operation
vorta copied to clipboard

Pre-Backup Bash script (.sh) not mounting (mount) drive

Open MrSiO opened this issue 8 months ago β€’ 30 comments

Description

Hi. I tried to launch a bash script in the "Pre-Backup" under "Shell Commands". This script is pretty simple. I use it to "mount" a drive before backup, and a simlar "Post-Backup" bash script to "unmout".

#!/bin/bash sudo /bin/mount -t cifs -o rw,user=me,uid=me,vers=3.0,credentials=/root/.mycredential //10.100.10.50/NAS-User-Backups /mnt/NAS-User-Backups/

As "user" if I manually lauch the script from folder, drive mounts without any problem and unmounts with my post-backup script. But when lauched at "pre-backup" like this in the APP, mount simply won't mount, BUT script is executing other commands within the script so I know Vorta has successfully lanched the script.

Command line set in the app under Pre-Backup: /home/user/BorgBackup/Scripts/Vorta-Backup-Script-PRE.sh

Note: my user is configured in "sudoers" to "sudo mount" without password.

Thx for any ideas...

Reproduction

  • [x] I tried to reproduce the issue.
  • [x] I was able to reproduce the issue.

OS

Linux Mint - 22.01

Version of Vorta

0.10.3

What did you install Vorta with?

Flatpak

Version of Borg

1.4.0

Logs

This is the log when launching the backup manually:

2025-03-18 16:11:01,169 - vorta.keyring.abc - DEBUG - No module named 'objc'
2025-03-18 16:11:01,175 - asyncio - DEBUG - Using selector: EpollSelector
2025-03-18 16:11:01,178 - vorta.keyring.abc - DEBUG - Using VortaSecretStorageKeyring
2025-03-18 16:11:01,178 - vorta.borg.borg_job - DEBUG - Using VortaSecretStorageKeyring keyring to store passwords.
2025-03-18 16:11:01,180 - asyncio - DEBUG - Using selector: EpollSelector
2025-03-18 16:11:01,183 - vorta.keyring.secretstorage - DEBUG - Found 1 passwords matching repo URL.
2025-03-18 16:11:01,185 - vorta.keyring.secretstorage - DEBUG - Retrieved password for repo /mnt/NAS-User-Backups/VORTA-MINIMAL
2025-03-18 16:11:21,273 - vorta.notifications - DEBUG - notification not suppressed
2025-03-18 16:21:37,412 - vorta.scheduler - DEBUG - Refreshing all scheduler timers
2025-03-18 16:21:37,420 - vorta.scheduler - INFO - Setting timer for profile 1
2025-03-18 16:21:37,424 - vorta.scheduler - DEBUG - Scheduling next run for 2025-03-24 18:53:07.159169
2025-03-18 16:21:37,432 - vorta.scheduler - DEBUG - Scheduler for profile 2 is disabled.

MrSiO avatar Mar 18 '25 20:03 MrSiO

Hey @MrSiO Since you have set NOPASSWD for root, this could be an issue related with the environment or file permissions. Also maybe try using full path and see if it fixes it, change sudo with /usr/bin/sudo.

VandalByte avatar Mar 20 '25 09:03 VandalByte

Thx. Will try that tonight and get back with the results. πŸ‘

MrSiO avatar Mar 20 '25 11:03 MrSiO

Hi @VandalByte. Changing sudo to /user/bin/sudo unfortunetly did not help. File permissions seem to be fine, but what is the "environment" possible issue?

Note: The NOPASSWD is not for root. It's for my user using the "mount" command only. Same user that is launching the bash...

MrSiO avatar Mar 20 '25 23:03 MrSiO

File permissions seem to be fine, but what is the "environment" possible issue?

By environment I meant the relative vs actual path.

I did some testing on this, trying to reproduce this with a custom bash script:

#!/bin/bash

dir_name="test"

mkdir "$dir_name"

if [ -d "$dir_name" ]; then
    echo "Directory '$dir_name' created successfully"
else
    echo "Failed to create the directory '$dir_name'"
fi

I added /home/vandal/Documents/bb.sh to Post-backup but when backup started, nothing happens but running the command mkdir /home/vandal/Documents/test in there, worked as expected.

Then I thought of just simplifying the code, cause it looked a bit too much for testing, into this:

#!/bin/bash

dir_path="/home/vandal/Documents/test"

mkdir "$dir_path"
echo "Done."

And this actually worked, the directory was created. So in conclusion, the issue you are facing has nothing to do with the permission or path related issue, it's more about the shell script itself.

You can try making a one liner and adding it directly into post-backup shell command.

PS: Vorta gives a notification "Pre-backup command returned non-zero exit code." on adding sudo inside the .sh script or in the post-backup shell command dialog and it's not shown in logs. To make up for using sudo, you could try running Vorta with elevated privileges.

VandalByte avatar Mar 21 '25 09:03 VandalByte

Thx alot @VandalByte I did try the oneliner but with all the arguments, Vorta just wont take it.
The string I tried (same as in my bash) is the following:

/usr/bin/sudo /bin/mount -t cifs -o rw,user=myself,uid=myself,vers=3.0,credentials=/home/myself/BorgBackup/.mycredential //10.100.100.50/NAS-Backups /mnt/NAS-Backups/

This command from CLI in terminal, copy/paste exactly as is from user "myself" does work and mount drive. Same command inserted inside a bash file executed by user "myself" also works. But this same command line aint accepted from Vorta as a sigle line in PRE backup. I then instead inserted the bash file in Vorta PRE backup command with no luck.

Do you suggest I create a variable like in your script below for my complete "mount" path? Not really sure I understand what would be placed inside the variable....

Thx for your help.

MrSiO avatar Mar 21 '25 19:03 MrSiO

You could try breaking down the paths in the command into variables within the .sh file. I'll also look into vorta to understand why it’s causing an issue, as both of my scripts (mentioned above) worked fine when run directly via the terminal. I'll update you if i find anything. Thanks.

VandalByte avatar Mar 23 '25 05:03 VandalByte

Thx! For now I managed to get around it my mounting my drive at boot. So present all the time. But will devinetly try this later on. Thx

MrSiO avatar Mar 23 '25 18:03 MrSiO

### Update: I found out some commands do work in the .sh when launched by Vorta. Applications like: notify-send (eg: "notify-send VORTA IN PROGRESS -t 15000) File & Directory creation Commdand redirect to file (eg: date >> file.txt)

While other dont work like: swaks (to send emails using CLI) mount and redirect to serial port (eg: whatever > /dev/ttyS0 )

kinda weird...

MrSiO avatar Mar 24 '25 23:03 MrSiO

FYI: I replaced the bash script with a perl script but unfortunately got the same results :(

MrSiO avatar Mar 26 '25 21:03 MrSiO

Update: I found out some commands do work in the .sh when launched by Vorta. Applications like:

notify-send (eg: "notify-send VORTA IN PROGRESS -t 15000) File & Directory creation Commdand redirect to file (eg: date >> file.txt)

While other dont work like: swaks (to send emails using CLI) mount and redirect to serial port (eg: whatever > /dev/ttyS0 )

kinda weird...

FYI: I replaced the bash script with a perl script but unfortunately got the same results :(

Thanks for testing! Apologies for the late reply; I was tied up with another commitment. I'll look into the issue now.

VandalByte avatar Mar 30 '25 02:03 VandalByte

Hey @MrSiO do you have the vorta development environment setup? I might have a fix but I don't have a way to know for sure without any mount testing. (I'm using a VM for development so can't be tested for sure). It will great if you could test it out for me when you can, use my dev branch

VandalByte avatar Mar 30 '25 13:03 VandalByte

Will gladly test it yes.

Question: On this dev version I can try to use my .sh script (wich includes mount) without any modifications?

MrSiO avatar Mar 30 '25 14:03 MrSiO

Question: On this dev version I can try to use my .sh script (wich includes mount) without any modifications?

Yes, you can. Just put it in a .sh file, give execute permissions, then pass it to vorta's pre/post backup command, like so /home/vandal/Documents/test.sh

EDIT: During my testing with different .sh scripts, the commands ran successfully, even sudo commands from inside a .sh file

VandalByte avatar Mar 30 '25 14:03 VandalByte

Can Flatpak and Dev version co-exist or should I first remove Flatpak?

MrSiO avatar Mar 30 '25 14:03 MrSiO

Dev version, you direcly install it from github, it doesn't actually install vorta to system, it just exist in a virtual env. So yes, they can co-exist. Here's the contributor guide. Use (my fork):

git clone https://github.com/VandalByte/vorta.git
cd vorta
git checkout dev-pre-post-cmd-bug

VandalByte avatar Mar 30 '25 14:03 VandalByte

I'm sorry. I'm a power user but I never developped.

I got the commands below completed and got the following results: Branch 'dev-pre-post-cmd-bug' set up to track remote branch 'dev-pre-post-cmd-bug' from 'origin'. Switched to a new branch 'dev-pre-post-cmd-bug'

Next step would be to do this part right? https://vorta.borgbase.com/contributing/#local-development-setup

MrSiO avatar Mar 30 '25 21:03 MrSiO

You must follow the guide first, only change is use my repo instead of git clone https://github.com/borgbase/vorta/ . Remember to install dependencies in a virtual env only, as mentioned in guide. You can google it, if you have any doubts regarding virtual env, there's tons of videos out there.

after you have done all that do,

git checkout dev-pre-post-cmd-bug
vorta

Vorta build will start running, then create a test repo and add the pre/post backup command. Thanks.

VandalByte avatar Mar 31 '25 01:03 VandalByte

@VandalByte Sorry, I was unable to make it work on my linux Mint. Is there any other way to test this?

Can you provide a .appimage or a .deb?
(I dont mind uninstalling the production version temporarly to install you dev version)

MrSiO avatar Apr 01 '25 17:04 MrSiO

@MrSiO I told you the easy way, so that you don't have uninstall anything, because I'm not sure it's going to work in your case. But if you are willing to uninstall vorta then, uninstall the one you currently have.

Then install it via pipx, if you don't have pipx, install it first with apt-get then run pipx ensurepath to add the pipx bin to PATH. Then install vorta:

pipx install vorta

It will take some time and install vorta, for me it's in /home/vandal/.local/pipx/venvs/vorta/ Then install the dependencies:

sudo apt update && sudo apt install -y \
  xvfb libssl-dev openssl libacl1-dev libacl1 build-essential borgbackup \
  libxkbcommon-x11-0 dbus-x11 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 \
  libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 libxcb-shape0 \
  libegl1 libxcb-cursor0

Then find these 2 files (path should almost be the same): /home/vandal/.local/pipx/venvs/vorta/lib/python3.11/site-packages/vorta/borg/create.py /home/vandal/.local/pipx/venvs/vorta/lib64/python3.11/site-packages/vorta/borg/create.py

Then, replace line 80:

proc = subprocess.run(cmd, shell=True, env=env)

with this:

proc = subprocess.run([cmd], env=env) if os.path.isfile(cmd) else subprocess.run(cmd, shell=True, env=env)

Finally run vorta from terminal, vorta then the GUI should popup, then do the rest as you will.

VandalByte avatar Apr 02 '25 07:04 VandalByte

Trying this today. Will keep you updated! Thx

MrSiO avatar Apr 04 '25 11:04 MrSiO

Hi. Unfortunetly I get this persisting error:

bradley@Bradley-Laptop:~$ pipx install vorta
Fatal error from pip prevented installation. Full pip output in file:
    /home/bradley/.local/pipx/logs/cmd_2025-04-04_13.38.14_pip_errors.log

**pip seemed to fail to build package:
    pyqt6**

Some possibly relevant errors from pip install:
    error: subprocess-exited-with-error
    error: metadata-generation-failed

Logfile says the following:

PIP STDERR

  error: subprocess-exited-with-error
  
  Γ— Preparing metadata (pyproject.toml) did not run successfully.
  β”‚ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "/home/bradley/.local/pipx/shared/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
          main()
        File "/home/bradley/.local/pipx/shared/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main
          json_out["return_val"] = hook(**hook_input["kwargs"])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/bradley/.local/pipx/shared/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 178, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-yi7ys4x3/overlay/lib/python3.11/site-packages/sipbuild/api.py", line 28, in build_wheel
          project = AbstractProject.bootstrap('wheel',
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-yi7ys4x3/overlay/lib/python3.11/site-packages/sipbuild/abstract_project.py", line 74, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/tmp/pip-build-env-yi7ys4x3/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 629, in setup
          self.apply_user_defaults(tool)
        File "/tmp/pip-install-a4gf4a0i/pyqt6_b05e6b75b6924023aace483753c5814d/project.py", line 66, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-yi7ys4x3/overlay/lib/python3.11/site-packages/pyqtbuild/project.py", line 51, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-yi7ys4x3/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 243, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "/tmp/pip-build-env-yi7ys4x3/overlay/lib/python3.11/site-packages/pyqtbuild/builder.py", line 49, in apply_user_defaults
          raise PyProjectOptionException('qmake',
      sipbuild.pyproject.PyProjectOptionException
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

Γ— Encountered error while generating package metadata.
╰─> See above for output.

**note: This is an issue with the package mentioned above, not pip.**

Thx for any input!

MrSiO avatar Apr 04 '25 17:04 MrSiO

This seems to be an issue with pyqt6 installation. can you try pipx install PyQt6 or sudo apt install python3-pyqt6. Then try installing vorta with pipx. Also install the sys dependencies first then try the whole process again.

Idk if this is required, I got this from google, some dependencies:

sudo apt install -y python3-dev build-essential qt6-base-dev qmake6

VandalByte avatar Apr 04 '25 18:04 VandalByte

Hi @VandalByte Yes I also found that info on google. Already installed and no luck. Dependency were also installed. No luck.

Tried the DEV version again, your first recommendation but got this error message:

Collecting cryptography>=2.0 (from SecretStorage>=3.2->keyring>=15.1->twine->-r requirements.d/dev.txt (line 15))
  Downloading cryptography-44.0.2.tar.gz (710 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 710.8/710.8 kB 2.9 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  Γ— Preparing metadata (pyproject.toml) did not run successfully.
  β”‚ exit code: 1
  ╰─> [6 lines of output]
      
      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/
      
      Checking for Rust toolchain....
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

Γ— Encountered error while generating package metadata.
╰─> See above for output.



MrSiO avatar Apr 04 '25 20:04 MrSiO

It's complaining about the missing rust binaries that are required to install cryptography, you can get it here, I do think dev version will be the best way to go.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

VandalByte avatar Apr 05 '25 01:04 VandalByte

It's complaining about the missing rust binaries that are required to install cryptography, you can get it here, I do think dev version will be the best way to go.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Hi @VandalByte Sorry... got a new error this time:

  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error


  Γ— Preparing metadata (pyproject.toml) did not run successfully.
  β”‚ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "/home/bradley/vorta/env/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
          main()
        File "/home/bradley/vorta/env/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main
          json_out["return_val"] = hook(**hook_input["kwargs"])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/bradley/vorta/env/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 178, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-2cn6ojzd/overlay/lib/python3.11/site-packages/sipbuild/api.py", line 28, in build_wheel
          project = AbstractProject.bootstrap('wheel',
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-2cn6ojzd/overlay/lib/python3.11/site-packages/sipbuild/abstract_project.py", line 74, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/tmp/pip-build-env-2cn6ojzd/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 629, in setup
          self.apply_user_defaults(tool)
        File "/tmp/pip-install-i1yete4u/pyqt6_b36a8dc5d59f4800b514528a64b48868/project.py", line 66, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-2cn6ojzd/overlay/lib/python3.11/site-packages/pyqtbuild/project.py", line 51, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-2cn6ojzd/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 243, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "/tmp/pip-build-env-2cn6ojzd/overlay/lib/python3.11/site-packages/pyqtbuild/builder.py", line 49, in apply_user_defaults
          raise PyProjectOptionException('qmake',
      sipbuild.pyproject.PyProjectOptionException
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

Γ— Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Any other ways to test this? I got an old laptop running Linux Mint (32 bit) so I can try anything...

MrSiO avatar Apr 07 '25 18:04 MrSiO

@MrSiO That's for the missing dependency - qmake

sudo apt-get update
sudo apt-get install qt6-base-dev qt6-qmake qt6-dev-tools

It seems you might encounter a bit more dependency issues, you can just put the errors in ChatGPT and that will save you a lot of time, no worries, let me know how it goes and thanks for taking your time to do this. Also, if you have broken packages, run this and try again.

pip3 cache purge

VandalByte avatar Apr 08 '25 01:04 VandalByte

Unfortunetly it seems qt6-base-dev and qt6-qmake arent available for my old 32bit Linux machine. Tried this procedure but only 64bit is available.

https://web.stanford.edu/dept/cs_edu/resources/qt/install-linux

And the sudo apt-get install qt6-base-dev qt6-qmake qt6-dev-tools could not be found in any of my repos... Tried to find repos for this on Mint 32bit without success... Sorry.

MrSiO avatar Apr 09 '25 20:04 MrSiO

Ah, alright then. I'll try a few things out, maybe run some more tests. If it turns out to be a bug, I'll add a PR to the main branch. Thanks

VandalByte avatar Apr 12 '25 05:04 VandalByte

Ah, alright then. I'll try a few things out, maybe run some more tests. If it turns out to be a bug, I'll add a PR to the main branch. Thanks

Keep me posted! Thx alot!

MrSiO avatar Apr 12 '25 15:04 MrSiO

Hi Sir! Any developement on this "feature" ? Thx

MrSiO avatar Apr 27 '25 20:04 MrSiO