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

Run automatically when pen-drive is plugged in #233

Closed
qazip opened this issue Mar 20, 2019 · 17 comments
Closed

Run automatically when pen-drive is plugged in #233

qazip opened this issue Mar 20, 2019 · 17 comments
Labels
status:planning For large features, plan it out before implementation

Comments

@qazip
Copy link

qazip commented Mar 20, 2019

Is your feature request related to a problem? Please describe.
I would like vorta to support running a backup whenever a pen-drive is plugged in.

Describe the solution you'd like

  • Plug in pen-drive;
  • Vorta backs up to pen-drive;
  • Unplug pendrive;
@m3nu
Copy link
Contributor

m3nu commented Mar 20, 2019

I have the same use case and fully agree that this would be nice.

I guess the solution would be different for each OS.

It may be able to use PR #231 to solve this. It can basically detect if Vorta already runs and then trigger some action. In the PR a window is opened, but it could as well trigger a backup.

Then the user could use the Distro's way to handle mount hooks to run e.g. vorta backup /mnt/xxx or so.

@qazip
Copy link
Author

qazip commented Mar 20, 2019

As long as plugging an usb-device (pen-drive) triggers the backup to the pen-drive, I am happy. It would be nice to have confirmation of backup at the end, such as a notification.

@MatejKovacic
Copy link

For Linux you can create udev rule or run script when a specific UUID of a disk is detected. This latter would be even better.

@m3nu
Copy link
Contributor

m3nu commented Apr 20, 2019

Then it should be possible to have a checkbox in Vorta and write some templates into those folders if they exist. Any link to this mechanism? Is it widely supported?

@MatejKovacic
Copy link

For UDEV rules:

  1. Create a file /etc/udev/rules.d/90-vorta.rules

  2. Content of this file:
    ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1c9e", ATTR{idProduct}=="f000", RUN+="runvortabackup.service"

  3. Create file /etc/systemd/system/runvortabackup.service

  4. Content of the file

[Unit]
Description=Run Vorta backup

[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/local/bin/.... (enter here)

[Install]
WantedBy=multi-user.target

  1. Reload UDEV rules:
    udevadm control --reload-rules

I am not absolutely sure it this is 100% correct (I am writing this from my mind, however, this is one possibility. Another, much better is to detect a disk device with specific UUID. I will describe this later.

@m3nu
Copy link
Contributor

m3nu commented Apr 21, 2019

Cool. Thanks for sharing. Since this modifies system folders, Vorta can't automatically change this when it's running as user application.

But I could see this added to a kind of "Cookbook" at first, so users can do it as one-time setup manually. Then once there is some experience with it it could be integrated and maybe ask for root-permissions using some mechanism that Gnome or other desktops probably have.

@MatejKovacic
Copy link

MatejKovacic commented Apr 21, 2019 via email

@Hofer-Julian
Copy link
Collaborator

Hofer-Julian commented Apr 21, 2019

Gksu is deprecated. Also, it might be wise if vorta continued to be fully usable without root privileges.

@MatejKovacic
Copy link

It seems that iu UDEV rules file you can use ENV{ID_FS_UUID}=="4A6F2ABC1232FA37", where 4A6F2ABC1232FA37 in UUID of a filesystem.

@oskarkook
Copy link

oskarkook commented Jul 9, 2019

Just as an example, without root access and with systemd you can place the following file in ~/.config/systemd/user/drive-backup.service:

[Unit]
description=Runs an automatic backup script

[Service]
Type=oneshot
ExecStart=/home/user/backup.sh

[Install]
WantedBy=run-media-user-mountpoint.mount

where run-media-user-mountpoint.mount corresponds to the drive's mount unit in systemctl --user list-units -t mount.

Then you need to enable it with systemctl --user enable drive-backup

@m3nu
Copy link
Contributor

m3nu commented Jul 10, 2019

That's cool. We should start documenting this somewhere? Like the Github wiki for starters. Later proper docs.

@Hofer-Julian
Copy link
Collaborator

That's cool. We should start documenting this somewhere? Like the Github wiki for starters. Later proper docs.

Well, it doesn't work without modifications to Vorta, right?

@m3nu m3nu added the status:planning For large features, plan it out before implementation label May 28, 2020
@m3nu
Copy link
Contributor

m3nu commented May 28, 2020

I'd like this too, but it's OS-specific to set up.

Vorta could support it by adding a CLI option. E.g. vorta create --profile ...

@m3nu
Copy link
Contributor

m3nu commented Dec 16, 2020

Thanks to @samuel-w , you can now script this. E.g. vorta --create nyx2@borgbase

More in this PR: #556

@m3nu
Copy link
Contributor

m3nu commented Dec 16, 2020

Closing this, since we probably can't do any deeper integration for now.

@m3nu m3nu closed this as completed Dec 16, 2020
@goebbe
Copy link
Contributor

goebbe commented Sep 30, 2024

I am a bit late to the party, but since it took me a while to get all the details right on my Linux computer (Linux Mint 22), I decided to post my working solution, here.
Hope this is useful to anybody.

Preparation:

  1. Plugin/ mount your USB-device
  2. Create a folder with your (new) repository name on the USB-device
  3. Create a new profile in Vorta for the USB-backup "USB_disk_backup"
  4. Create a repository and choose the path for your (new) repo on the USB-device
  5. Add sources and test the new repository by creating a manual backup, using Vorta

Set up automatic Vorta backup, when a specific .mount unit becomes available:
List all .mount units of the current user to identify the .mount-unit of the USB-device:
systemctl --user list-units -t mount

Identify the .mount unit for your usb-device. For example for an Intatek USB-device, the following unit might be available:
media-yourusername-Inateck.mount

Place the following systemd .service-file in ~/.config/systemd/user/auto-usb-vorta-backup.service.
Don't forget to adapt/ edit the name of the .mount unit and check the profile name.

[Unit]
description=Runs an automatic vorta backup when the specified usb .mount-unit becomes available

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'vorta --create USB_disk_backup'

[Install]
WantedBy=media-yourusername-Inateck.mount

Start the service:
systemctl start --user auto-usb-vorta-backup.service
Enable the service:
systemctl enable --user auto-usb-vorta-backup.service

Now, when you plugin/ mount your USB-device, the profile "USB_disk_backup" will be started.
IMPORTANT: For this to work, Vorta has to be running (in the background) on your computer.
It might be useful to enable "Automatically start Vorta at login" in the Vorta settings.

Useful commands, for maintenance:
Check the status of the service:
systemctl status --user auto-usb-vorta-backup.service

After changing the .service file, one has to reload:
systemctl --user daemon-reload

Detailed systemd logs:
journalctl --user -xeu auto-usb-vorta-backup.service

@goebbe
Copy link
Contributor

goebbe commented Sep 30, 2024

If you do not want Vorta to run in the background permanently, you could adapt the ExecStart line as follows:
ExecStart=/bin/bash -c 'if ! pidof -x "vorta" >/dev/null; then vorta & sleep 5; fi && vorta --create USB_disk_backup'

This command first checks if Vorta is already running.

  • If Vorta is not running: First start Vorta, then, sleep for 5 seconds.
  • Anyway, create the USB_disk_backup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:planning For large features, plan it out before implementation
Projects
None yet
Development

No branches or pull requests

6 participants