# Wild Card questions file copy with fs-ops

**URL:** <https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181>\
**Category:** General\
**Created:** [25 November 2018 16:24 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181 "2018-11-25T16:24:16Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [25 November 2018 16:24 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/1 "2018-11-25T16:24:16Z")

</div>

I had an accident with a corrupt (brand new!) SD card in one of my Pi's today, and I didn't have backups of the three hours I worked on Node-RED and Home Assistant yesterday. Luckily I managed to mount the card in a reader and use Recuva on a pc to find everything, so I lost nothing. But it scared the living crap out of me, so I want a fully automated system that copies (wich schedex) the files that I need to backup every night to a share on my server. But I have one slight problem with that: I want to copy all \*.yaml files to that directory. Do I need to make one node for each of them, or can I in some way do a wild card copy? Either I didn't find the full instructions, or they imply that the reader knows a lot more about this stuff than I do. 😊

---

<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:** [25 November 2018 16:49 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/2 "2018-11-25T16:49:36Z")

</div>

Use one of the backup systems such as backintime or borgbackup.

---

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [25 November 2018 16:53 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/3 "2018-11-25T16:53:14Z")

</div>

Thanks, but I would prefer the simple copy function in Node-RED, which I can spread out to my six Pi's in a few minutes without installing anything else. I already have the system set up, I only need the wildcard stuff working.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 November 2018 16:56 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/4 "2018-11-25T16:56:59Z")

</div>

you can always call out to a system copy command with the exec node.

---

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [25 November 2018 16:58 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/5 "2018-11-25T16:58:20Z")

</div>

Probably, but then I wouldn't easily get a message telling me if it went wrong, would I? The fs-ops can do that.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 November 2018 17:35 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/6 "2018-11-25T17:35:22Z")

</div>

well it returns stdout and stderr so yes it should.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [25 November 2018 17:41 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/7 "2018-11-25T17:41:54Z")

</div>

> [@dceejay](#):
>
> well it returns stdout and stderr so yes it should.

Good point Dave, I always forget that!

---

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [25 November 2018 17:58 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/8 "2018-11-25T17:58:00Z")

</div>

That works, thanks! But it doesn't give any messages when the copy didn't fail, and I think that would be easier to catch than a message when it fails. Because the fail messages can have different reasons (directory not found, copy protected and so on), I'm afraid that I won't get the message if something ahppens. Is there a way to get a confirmation? Maybe with afile excists or something?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [25 November 2018 18:35 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/9 "2018-11-25T18:35:13Z")

</div>

Have you debugged all the outputs of the node?  
You can also use a status node to monitor the exec node!

---

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [25 November 2018 18:40 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/10 "2018-11-25T18:40:29Z")

</div>

Yeah, I have a debug on it, and it doesn't show anything at all when the copy is successful. But I think I can use fs-ops' File Access node to check for the files and send a message if they don't excist.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [25 November 2018 18:43 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/11 "2018-11-25T18:43:22Z")

</div>

Can you post the flow?

---

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [25 November 2018 18:45 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/12 "2018-11-25T18:45:10Z")

</div>

Sorry, my mistake. I was on the wrong output of the exec node. It gives a payload of 0 when it's done.

Here's the flow. Note that it uses fs-ops to creat the directory with date and time of copy:

`[{"id":"913db8eb.c67c9","type":"debug","z":"50a57e0b.d8ff6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":930,"y":540,"wires":[]},{"id":"9d814f4c.dd15e8","type":"exec","z":"50a57e0b.d8ff6","command":"sudo cp","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Kopiere","x":720,"y":500,"wires":[["913db8eb.c67c9"],["913db8eb.c67c9"],["913db8eb.c67c9"]]},{"id":"276ecca6.eb748c","type":"exec","z":"50a57e0b.d8ff6","command":"sudo cp","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Kopiere","x":720,"y":560,"wires":[["913db8eb.c67c9"],["913db8eb.c67c9"],["913db8eb.c67c9"]]},{"id":"5a83d01e.f8ec5","type":"exec","z":"50a57e0b.d8ff6","command":"sudo cp","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Kopiere","x":720,"y":620,"wires":[["913db8eb.c67c9"],[],["913db8eb.c67c9"]]},{"id":"770fec07.dd12fc","type":"function","z":"50a57e0b.d8ff6","name":"Kopier YAML til katalog","func":"var d = new Date();\nvar hours = d.getHours();\nvar minutes = d.getMinutes();\nvar seconds = d.getSeconds();\nvar year = d.getFullYear();\nvar month = d.getMonth()+1;\nif (month < 10) {\n month = '0'+ month;\n}\nvar day = d.getDate();\nif (day < 10) {\n day = '0'+ day;\n}\nif (hours < 10) {\n hours = '0'+ hours;\n}\nif (minutes < 10) {\n minutes = '0'+ minutes;\n}\nif (seconds < 10) {\n seconds = '0'+ seconds;\n}\nvar global_n = year+'-'+month+'-'+day+','+hours+'.'+minutes;\nvar rotkatalog = '/home/pi/Desktop/Sikkerhetskopier/'; \nvar filer = '/home/homeassistant/.homeassistant/*.yaml ';\nmsg.payload = filer+rotkatalog+global_n;\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":500,"wires":[["9d814f4c.dd15e8"]]},{"id":"aed567f6.1da2a8","type":"function","z":"50a57e0b.d8ff6","name":"Kopier XML til katalog","func":"var d = new Date();\nvar hours = d.getHours();\nvar minutes = d.getMinutes();\nvar seconds = d.getSeconds();\nvar year = d.getFullYear();\nvar month = d.getMonth()+1;\nif (month < 10) {\n month = '0'+ month;\n}\nvar day = d.getDate();\nif (day < 10) {\n day = '0'+ day;\n}\nif (hours < 10) {\n hours = '0'+ hours;\n}\nif (minutes < 10) {\n minutes = '0'+ minutes;\n}\nif (seconds < 10) {\n seconds = '0'+ seconds;\n}\nvar global_n = year+'-'+month+'-'+day+','+hours+'.'+minutes;\nvar rotkatalog = '/home/pi/Desktop/Sikkerhetskopier/'; \nvar filer = '/home/homeassistant/.homeassistant/*.xml ';\nmsg.payload = filer+rotkatalog+global_n;\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":560,"wires":[["276ecca6.eb748c"]]},{"id":"41b95b98.fdf1fc","type":"function","z":"50a57e0b.d8ff6","name":"Kopier entity registry til katalog","func":"var d = new Date();\nvar hours = d.getHours();\nvar minutes = d.getMinutes();\nvar seconds = d.getSeconds();\nvar year = d.getFullYear();\nvar month = d.getMonth()+1;\nif (month < 10) {\n month = '0'+ month;\n}\nvar day = d.getDate();\nif (day < 10) {\n day = '0'+ day;\n}\nif (hours < 10) {\n hours = '0'+ hours;\n}\nif (minutes < 10) {\n minutes = '0'+ minutes;\n}\nif (seconds < 10) {\n seconds = '0'+ seconds;\n}\nvar global_n = year+'-'+month+'-'+day+','+hours+'.'+minutes;\nvar rotkatalog = '/home/pi/Desktop/Sikkerhetskopier/'; \nvar filer = '/home/homeassistant/.homeassistant/.storage/core.entity_registry ';\nmsg.payload = filer+rotkatalog+global_n;\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":620,"wires":[["5a83d01e.f8ec5"]]},{"id":"ec4fb77.fd8fbc8","type":"delay","z":"50a57e0b.d8ff6","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":260,"y":560,"wires":[["770fec07.dd12fc","aed567f6.1da2a8","41b95b98.fdf1fc"]]},{"id":"d7b1c6e8.cec2a","type":"inject","z":"50a57e0b.d8ff6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":560,"wires":[["c6f5cda1.3cac4","ec4fb77.fd8fbc8"]]},{"id":"c6f5cda1.3cac4","type":"function","z":"50a57e0b.d8ff6","name":"Lage katalog","func":"var d = new Date();\nvar hours = d.getHours();\nvar minutes = d.getMinutes();\nvar seconds = d.getSeconds();\nvar year = d.getFullYear();\nvar month = d.getMonth()+1;\nif (month < 10) {\n month = '0'+ month;\n}\nvar day = d.getDate();\nif (day < 10) {\n day = '0'+ day;\n}\nif (hours < 10) {\n hours = '0'+ hours;\n}\nif (minutes < 10) {\n minutes = '0'+ minutes;\n}\nif (seconds < 10) {\n seconds = '0'+ seconds;\n}\nvar global_n = year+'-'+month+'-'+day+','+hours+'.'+minutes;\nmsg.payload = global_n\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":340,"wires":[["99e6bbb.3a3b448"]]},{"id":"99e6bbb.3a3b448","type":"fs-ops-mkdir","z":"50a57e0b.d8ff6","name":"Lage katalog med dato og tidspunkt","path":"/home/pi/Desktop/Sikkerhetskopier","pathType":"str","dirname":"payload","dirnameType":"msg","mode":"777","fullpath":"directory","fullpathType":"msg","x":580,"y":340,"wires":[[]]}]`

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [25 November 2018 18:47 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/13 "2018-11-25T18:47:52Z")

</div>

So if you get a code 0 you know it was successful.

---

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [25 November 2018 18:48 UTC](https://discourse.nodered.org/t/wild-card-questions-file-copy-with-fs-ops/5181/14 "2018-11-25T18:48:22Z")

</div>

Yep. 🙂
