# Using the exec node to automate database backups

**URL:** <https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292>\
**Category:** General\
**Tags:** docker\
**Created:** [27 September 2024 04:10 UTC](https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292 "2024-09-27T04:10:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blobby](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@Blobby](https://discourse.nodered.org/u/Blobby)\
**Post date:** [27 September 2024 04:10 UTC](https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292/1 "2024-09-27T04:10:05Z")

</div>

hi  
I'm fairly new to node-red and am trying to automate execution of a command.

A bit of background. I am setting up a number of IOT sensors to collect data for a project I have. I am using a MING (Mosquitto, InfluxDB, Node-red, and Grafana) stack to collect the data points from the sensors, store them (influxdb) and display them. For now the server is running on a raspberry pi. I've used docker to set up the MING stack and it is running well.

I now would like to set up a backup for the InfluxDB database. I have mounted a shared folder back to my NAS at /home/dr/lab\_data to hold it. Docker provides a command to export containers (eg Influxdb) into a .tar file.

```auto
sudo docker export -o /home/dr/lab_data/ influxdb

```

I can execute the command manually and it creates a .tar file in the location and now would like to automate this in code red.

I haven't been able to get the exec node to work.

simply inserting the above command returns error 127 with ...  
Command failed: sudo docker export -o /home/dr/lab\_data/test influxdb  
/bin/bash: line 1: sudo: command not found

I have tried including the command in the injected message payload but this doesn't work.

any constructive suggestions would be welcome

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 September 2024 06:58 UTC](https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292/2 "2024-09-27T06:58:10Z")

</div>

You will not be able to execute sudo commands from node-red. You will need to add the user to the sudo group, or do it a 'more' node-red-way, use a node like [dockerode](https://flows.nodered.org/node/node-red-contrib-dockerode) to execute docker commands

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [27 September 2024 09:35 UTC](https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292/3 "2024-09-27T09:35:49Z")

</div>

This is how I backup the influx database from an Exec node.  
Tar file is generate in the /home/nodered/dbs/backup\_ex directory.

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/32da85569f91a6ecfff31299779dfc43c4327a5f.png)

Don't know if it will work in Docker.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 September 2024 10:16 UTC](https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292/4 "2024-09-27T10:16:32Z")

</div>

> [@bakman2](#):
>
> You will not be able to execute sudo commands from node-red.

This is not strictly true. You could edit sudoers to turn off the need for a password prompt for that command. Of course, this may be something of a security issue so should only be done after careful thought about possible consequences.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 September 2024 11:11 UTC](https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292/5 "2024-09-27T11:11:00Z")

</div>

> [@Blobby](#):
>
> ```auto
> sudo docker export -o /home/dr/lab_data/ influxdb
> 
> ```
> 
> I can execute the command manually

Is node red also running in Docker? If so, does that command run if you execute it from inside the node red docker container?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 December 2024 11:11 UTC](https://discourse.nodered.org/t/using-the-exec-node-to-automate-database-backups/91292/6 "2024-12-26T11:11:42Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
