Wrote a simple CLI binary/tool to backup WLED presets & config

Spent a couple of hours writing a tool to backup WLED configuration to have reproducable setups, backups and possibility to sync presets across devices. From my Github:

I put a lot of effort in getting my presets right for all of my WLED devices. The cheap ESP8266’s I buy from AliExpress aren’t resistant to failure however and reflashing WLED on a new ESP means that I would have to recreate my presets from scratch. Luckily WLED’s JSON API exposes an endpoint to retrieve your presets & configuration as JSON files.

This tool does nothing more than calling that endpoint and writing it to a file on the system in parallel. This way you can backup your files via e.g a cronjob.

Currently running this via a cronjob on my server which will backup the files every monday so I never lose my precious presets.

Downloads available over at thibmaek/wled-backup for Intel 64, ARM (rpi / M1 Mac), Windows, Linux and macOS.

1 Like

A binary (unsigned) may not be to everyone’s liking.

A simpler command line script can do it as well:

curl -s http://$1/presets.json -o presets-$1.json >/dev/null
res=$?; if [ $res -ne 0 ]; then echo "Error saving cfg.json $1 ($res)"; return $res; fi
curl -s http://$1/cfg.json -o cfg-$1.json >/dev/null
res=$?; if [ $res -ne 0 ]; then echo "Error saving presets.json $1 ($res)"; return $res; fi

And then call it as backup.sh 192.168.x.x
An easy modification will work for windows too.

1 Like

I know, most of my automation/scripting happens in Bash but I’m steering away from it more and more because of the difficult parts:

  • error handling
  • concurrency / parallelisation
  • having a nice syntax
  • dependencies that need manual user install before it works
  • working around dependencies not being available
  • working around GNU/BSD differences in tools like grep/find/sed

I think Go is the best alternative here: minimal setup, compiles to every platform, lightweight binaries, and ticks the boxes for all the above.

For example: the script you post is perfect for a simple backup. The tool I wrote will get the hostname and save the file as <hostname>.presets.json concurrently for each host. That would be something like this in Bash to have it concurrently:

./backup.sh wled-tv.local & ./backup.sh wled-desk.local & ...

Or use xargs, but again that behaves differently across GNU/BSD

And for getting the hostname for the file that would mean a looooot of Bash code to do simple things like error handling the HTTP response, interpolating the name etc.

Anyway, do what suits you best of course! My repo is just for those that need a no hassle solution to a problem: backing up files. You can of course always compile from source to get the same binary if you don’t trust binaries from strangers (which I get)

The more options a user has, the better.

Is your link to source code? That is what I think some WLED users might be wondering.

I appreciate you sharing your work. I’m not a “go” person, so perhaps the source is there and I simply overlooked it?

Link is pointing to the Github repo rather than to a binary download and the releases are created automatically by Github Actions

1 Like