Cifs share by using exec node

#1

Hi, i am just looking for a solution, backing up my pi over my network. I have a windows server, which only starts for backup routines.
What i would like to do is the following scenario:
Every night the bigtimer node is waking up the windows pc via wol (works fine).
After a delay with the bigtimer node, the RasPi should mount the windows share and backing up itself to the shared folder. When it`s done, windows is shutting down.
Manually sharing via cifs works fine (sudo mount -t cifs //windows-server/e /media/backup-ssd -o username=user,password=password,rw,file_mode=0777,dir_mode=0777,vers=1.0) but not within nodered by using the exec node (./home-server-mount.sh).
content of the script:
#!/bin/bash
sudo mount -t cifs //windows-server/e /media/backup-ssd -o username=user,password=password,rw,file_mode=0777,dir_mode=0777,vers=1.0
exit
The result is an error (126).
I´m new with nodered and being thankful for hints. Maybe there are other ideas for doing such a job.

Thanks Jesco

#2

You can't run things as sudo inside an exec node - as that counts as a privilege escalation which is a security no-no.

#3

As always, you could get round this by allowing the user running Node-RED to escallate without a password for the mount command.

However, surely it would be better to use the OS itself to run a script to wake up and mount the share. Put that in a scheduled task running as root.

While Node-RED is great, you shouldn't assume to use it for everything! :wink:

1 Like
#4

I agree here - just because we have a hammer - not every problem is a nail.

Setup a cron job to run your script (as root) - then append whatever additional commands (after a suitable pause) that you wish to use to perform the backup

You could also install the WSL (subsystem for Linux) on windows and then use Rsync to perform an incremental backup to the machine over SSH

Craig

#5

No need for WSL for this. You can get SSH & RSYNC for Windows natively too. There are also SSH based backup tools that will do the job. Indeed there are plenty of tools that will do this.

#6

At the end, the backup itself should not be a big challenge. I love nodered and i am about to use it as a "swiss army knife". But as TotallyInformation wrote, "you shouldn't assume to use it for everything!". The only challenge i see, is the synchronizing of the cron job and the startup flow for the windows computer (i only want to start for the backup). At the end it should work like this: Windows starting at 4 am (nodered), on 4.10 am the cron job is mounting the windows share on the PI and starts the backup. After that (5 am) the backup share is gonna be unmount and the windows computer is shutting down. Easy in theory :wink:

#7

That is also easy - there are well trodden paths for this kind of thing (helps if you know computing history!).

In your CRON job, include the creation/update of a file containing a machine readable timestamp (I recommend ISO format). Then your flow can read the file & make sure that the timestamp is current before continuing - if it isn't, you can delay it by a couple of minutes and loop.