Wild Card questions file copy with fs-ops

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. :blush:

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

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.

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

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

well it returns stdout and stderr so yes it should.

1 Like

Good point Dave, I always forget that!

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?

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

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.

Can you post the flow?

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":[[]]}]

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

Yep. :slight_smile: