The Unimus backup exporter exports backups from your Unimus server, stores them locally, and pushes them to a git repo if desired. It ships as two fully-featured implementations - a Bash script for Linux/macOS and a PowerShell script for Windows (it also runs on Linux/macOS) - that read the same config and produce the same backups. Use whichever fits your environment.
The Bash version (unimus-backup-exporter.sh) requires bash, curl, jq, and base64. The PowerShell version (unimus-backup-exporter.ps1) requires pwsh (PowerShell 7+).
Pushing to git (export_type=git) additionally needs git for either version, plus ssh-keyscan when using the ssh protocol.
The PowerShell version runs on Windows, Linux, and macOS. To keep filenames valid on Windows it timestamps backups in UTC without :, so its filenames differ slightly from the Bash version's (which uses local time with :).
To use the exporter, you must configure the script's env file with your settings. The script can extract all backups, or just the latest backups, depending on configuration.
If you are using this script to push backups to git, it will create a local git directory based on the settings in your env file, and then push backups to that repo.
-
Configure the env with the appropriate variables for your install as described in the Configuration File section.
-
To execute the script, run one of the following in the script directory:
./unimus-backup-exporter.sh # Bash
pwsh ./unimus-backup-exporter.ps1 # PowerShellAfter the script runs, you will find your backups nested in a "backups" folder. Each device's backups are in their own folder, labeled by the device address and the Unimus device ID:
backups/
10.0.0.1 - 72/
Backup 10.0.0.1 2023-05-31-10:30:50-AEST 72.txt
10.0.0.3 - 73/
Backup 10.0.0.3 2023-05-31-10:31:02-AEST 73.txt
The folder/file naming is configurable: separator="_" replaces the spaces (e.g. 10.0.0.1_-_72/), and device_name_field="description" names folders by hostname (e.g. router1 - 72/). See the Configuration File section.
Both versions read the same unimus-backup-exporter.env, produce the same backup contents, and push to git the same way. They differ only in the filename timestamp: the Bash version uses local time (with :), while the PowerShell version uses UTC without : so names stay valid on Windows. A shared test suite verifies each version against its expected output.
The PowerShell version requires PowerShell 7 or newer. Windows ships with Windows PowerShell 5.1, which is not supported - double-clicking the .ps1 or launching it from a powershell prompt uses 5.1, and the script will refuse to run with a version error.
Install PowerShell 7 once, for example with winget:
winget install --id Microsoft.PowerShell --source wingetAlternatively, download the MSI from the PowerShell releases page. PowerShell 7 installs alongside Windows PowerShell as a separate pwsh command; it does not replace 5.1.
Then run the script with pwsh from the script's directory:
cd C:\path\to\unimus-backup-exporter
pwsh .\unimus-backup-exporter.ps1To run it on a schedule, see the Automating the exporter section.
The most basic requirements for the script to operate are:
| Setting | Value |
| ------------------- | ----------------------- |
| unimus_server_address | "http://192.168.0.1:8085" |
| unimus_api_key | "your unimus api key" |
| backup_type | "all" or "latest" |
| export_type | "git" or "fs" |
backup_type
- "all" will download all backups when the script is run
- "latest" will download only the latest backup each time the script is run
export_type
- "git" will push the backups to your git repo
- "fs" will keep the backups on the local fs
If your Unimus server uses a self-signed certificate, you can skip TLS certificate verification by uncommenting insecure="-k" in the env file. Leave it commented out otherwise.
By default the backup folder and file names use spaces as separators (e.g. 10.0.0.1 - 1/Backup 10.0.0.1 ... 1.txt). To use a different separator - underscores, say, which are easier to work with on the command line - set separator="_" in the env file. Leaving it unset keeps the original spaced names.
By default device folders are named by the device's IP address. To name them by the device description instead - typically the hostname, which is friendlier in DNS-managed environments - set device_name_field="description" in the env file. Devices without a description fall back to their address.
For large installations, page_size (default 50) controls how many records the script requests per API call. It bounds the JSON returned per request; leaving it unset keeps the default.
In addition to these basic requirements, using git requires some of these additional settings:
| Setting | Value |
| ----------------- | ---------------------- |
| git_username | "foo" |
| git_password | "bar" |
| git_email | foo@bar.com |
| git_server_protocol | "http", "https" or "ssh" |
| git_server_address | "192.168.1.1" |
| git_port | "80" |
| git_repo_name | "Foo/Backups.git" |
| git_branch | "master" |
Depending on your git server you may not require a password (the password is only required for the http/https protocols).
To run your script periodically, the most common solution is scheduling a cron job. Adding the following line to crontab -e will set up the script to run every night at 3AM:
0 3 * * * /path-to-script/unimus-backup-exporter.sh
On Windows, schedule the PowerShell version with Task Scheduler, running pwsh -File C:\path\to\unimus-backup-exporter.ps1.
A shared test suite under tests/ runs both the Bash and PowerShell versions against a mock Unimus API and checks each produces its expected backups (plus identical git behavior). Run everything with:
tests/run.shSee tests/README.md for details on the layers and how to run them individually.