Borg Backup is available in the Synocommunity repositiory and can be installed via the packet center.
Out of the box, backing up data from the syno NAS towards another location worked flawlessly.
But backing up data to the NAS using borg on another machine always resulted in the following error:
mypc> borg init --info --encryption=repokey-blake2 backup@syno:/volume1/borg/mypc
Remote: sh: borg: command not found
Connection closed by remote host. Is borg working on the server?
On the NAS I had created a user called backup
which I use for backup jobs. When connecting to the NAS via ssh backup@syno
and typing in borg
everything worked just great.
On the other hand, when running the command via ssh backup@syno 'borg'
the following error was returned:
sh: borg: command not found
Looks familiar, doesn´t it?
Lets compare the shell environments in both cases:
-
Running
env
via an interactive ssh login shell returns the pathPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
-
Running
ssh backup@syno 'env'
returnsPATH=/usr/bin:/bin:/usr/sbin:/sbin
Now lets check via the interactive shell where the borg
command is located on the syno box:
syno> which borg
/usr/local/bin/borg
As /usr/local/bin/
is in the path of an interactive login shell but not of an non-interactive one, the behaviour is explained. But how to solve this?
Solutions which modify the way borg is called on the source machine are out for me as I want to avoid messing around with custom borg installation.
But OpenSSHd has an mechanism which allows to set user specific environment variables for non-interactive shells.
Simply create a file ~/.ssh/environment
in the users homedirectory (where the authorized_keys
files is) and put the PATH you want into it:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
Now you need to enable user specific environment in the shhd config. Open /etc/ssh/sshd_config
(on the syno box) for editing, search for PermitUserEnvironment
and make sure the line look like this:
PermitUserEnvironment yes
Save it and restart the NAS.
After the restart, running ssh youruser@syno 'borg'
should work and you can use borg to backup data to your NAS without using SSHFS or similar things.