Automating Upgrades with MariaDB.Org Downloads REST API
The MariaDB Foundation maintains a Downloads REST API. See the Downloads API documentation to find out all the tasks that you can accomplish with this API. Generally speaking, we can say that it provides information about MariaDB products and available versions. This allows to easily automate upgrades for MariaDB and related products.
Usage Example: Checking When a Version Becomes GA
A trivial use case is to write a script that checks the list of MariaDB GA major versions and, when something changes, send us an email. So we can test the newest GA version and eventually install it.
The script in this example will be extremely simple. We'll do it this way:
- Retrieve the JSON object describing all MariaDB versions.
- For each element of the array, only show the
release_id
andrelease_status
properties, and concatenate them. - Apply a filter, so we only select the rows containing 'stable' but not 'old' (so we exclude 'Old Stable').
- From the remaining rows, only show the first column (the version number).
- If the results we obtained are different from the previously written file (see last point) send an email.
- Save the results into a file.
This is something that we can easily do with a Unix shell:
#!/bin/bash current_ga_versions=$( curl https://downloads.mariadb.org/rest-api/mariadb/ | \ jq -r '.major_releases[] | .release_id + " " + .release_status' | \ grep -i 'stable' | grep -v 'old' | \ cut -d ' ' -f 1 ) touch ga_versions previous_ga_versions=$( cat ga_versions ) if [ "$current_ga_versions" != "$previous_ga_versions" ]; then mail -s 'NOTE: New MariaDB GA Versions' [email protected] <<< 'There seems to be a new MariaDB GA version! Yay!' fi
The only non-standard command here is jq. It is a great way to manipulate JSON documents, so if you don't know it you may want to take a look at jq documentation.
Content initially contributed by Vettabase Ltd.