Skip to content

Instantly share code, notes, and snippets.

@danojpa
Created April 9, 2021 16:19
Show Gist options
  • Save danojpa/df93c3fd62ab1d91d67136f691e0b6cf to your computer and use it in GitHub Desktop.
Save danojpa/df93c3fd62ab1d91d67136f691e0b6cf to your computer and use it in GitHub Desktop.
Backup con Node Red desde teclado Telegram

Raspberry pi, backup desde un teclado Telegram.

[{"id":"c5cd491e.f67da8","type":"inject","z":"d1a5766b.9f3cf8","name":"backup_pi","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"backup_pi","vt":"string"}],"repeat":"","crontab":"00 03 * * 6","once":false,"onceDelay":0.1,"topic":"backup_pi","payload":"","payloadType":"date","x":170,"y":120,"wires":[["5f1ff6f5.dd5418"]]},{"id":"57a461b6.53d05","type":"inject","z":"d1a5766b.9f3cf8","name":"backup_flows","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 04 * * 6","once":false,"onceDelay":0.1,"topic":"backup_flows","payload":"","payloadType":"date","x":180,"y":200,"wires":[["5f1ff6f5.dd5418"]]},{"id":"959c5010.54c6b","type":"inject","z":"d1a5766b.9f3cf8","name":"backup_datos","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"backup_datos","payload":"","payloadType":"date","x":170,"y":280,"wires":[["5f1ff6f5.dd5418"]]},{"id":"b7829f19.365eb","type":"exec","z":"d1a5766b.9f3cf8","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":530,"y":120,"wires":[["8fb3446c.091548"],[],["a3ac0c8d.8b78a"]]},{"id":"5f1ff6f5.dd5418","type":"function","z":"d1a5766b.9f3cf8","name":"copiar","func":"var str = msg.topic\nif(str == \"backup_pi\"){\n msg.payload = \"sudo dd bs=4M if=/dev/sdb of=/media/PenDrivePi4/Backup/PiOS.img\"; \n}\nelse if(str == \"backup_flows\"){\n msg.payload = \"sudo cp /home/pi/.node-red/flows_raspberrypi.json /media/PenDrivePi4/Backup/flows_raspberrypi.json\" ;\n}\nelse if(str == \"backup_datos\"){\n msg.payload = \"our date\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":120,"wires":[["b7829f19.365eb"]]},{"id":"8fb3446c.091548","type":"debug","z":"d1a5766b.9f3cf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":700,"y":60,"wires":[]},{"id":"a3ac0c8d.8b78a","type":"debug","z":"d1a5766b.9f3cf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":180,"wires":[]},{"id":"df12ca42.f5a118","type":"function","z":"d1a5766b.9f3cf8","name":"backup ?","func":"context.flow.backup = { messageId : msg.payload.messageId, chadId : msg.payload.chadId };\nif(msg.payload.content.includes(\"/start\")){\n var opts = {\n resize_keyboard: true,\n one_time_keyboard: true,\n reply_markup: JSON.stringify({\n \"inline_keyboard\": [[\n {\"text\":\"Backup pi\",\"switch_inline_query_current_chat\":\"backup_pi\"}],\n [{\"text\":\"Backup flow Node Red\",\"switch_inline_query_current_chat\":\"backup_flows\"}],\n [ {\"text\":\"Backup datos\",\"switch_inline_query_current_chat\":\"backup_datos\"}\n ]]\n })\n }\n msg.payload.sentMessageId = context.flow.backup.messageId;\n msg.payload.options = opts;\n msg.payload.content = \"teclado\";\n return [null,msg];\n}\nelse if(msg.payload.content.includes(\"backup_pi\")){\n msg.payload = \"sudo dd bs=4M if=/dev/sdb of=/media/PenDrivePi4/Backup/PiOS.img\"; \n}\nelse if(msg.payload.content.includes(\"backup_flows\")){\n msg.payload = \"sudo cp /home/pi/.node-red/flows_raspberrypi.json /media/PenDrivePi4/Backup/flows_raspberrypi.json\" ;\n}\nelse if(msg.payload.content.includes(\"backup_datos\")){\n msg.payload = \"our date\";\n}\nreturn [msg,null];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":380,"y":340,"wires":[["b7829f19.365eb"],["f8cab9ef.8ce608"]]},{"id":"8950dfa.e3df22","type":"telegram receiver","z":"d1a5766b.9f3cf8","name":"","bot":"69e42384.abe61c","saveDataDir":"","filterCommands":false,"x":170,"y":360,"wires":[["df12ca42.f5a118"],[]]},{"id":"ae5d725d.5e627","type":"comment","z":"d1a5766b.9f3cf8","name":"https://www.raspberrypi.org/documentation/linux/filesystem/backup.md","info":"","x":400,"y":440,"wires":[]},{"id":"f8cab9ef.8ce608","type":"telegram sender","z":"d1a5766b.9f3cf8","name":"","bot":"69e42384.abe61c","haserroroutput":false,"outputs":1,"x":590,"y":380,"wires":[[]]},{"id":"69e42384.abe61c","type":"telegram bot","botname":"our_bot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment