unifi backup - DaveL17/indigo-scripts GitHub Wiki
The Unifi controller is capable of performing configuration backups automatically and -- depending on the user's configuration -- stores those files locally. If the controller becomes unresponsive or the local storage becomes unreadable, those backups may be lost -- making recovery difficult or impossible. The purpose of this script is to make an additional copy of the backup files in another location to provide additional resiliency.
This approach has been tested against macOS 15.1.1
and a Unifi Cloud Key Gen 1 running controller version 7.2.97
.
Your environment might be different and these steps might need to be modified. Running the script from within a
virtual environment is not recommended.
Warning
By using this script, you agree that you're using it at your own risk.
To make the script run as autonomously as possible, you need to create key-based authentication credentials so that the script can log into the controller without needing to enter a username or password (ey-based authentication is considered superior to username/password logins).
Generate SSH Key Pair (if you don't already have one): On the local machine (the one you’ll use to run the script), generate an SSH key pair if you don't already have one:
`ssh-keygen -t ed25519`
Follow the prompts to save the key. By default, it'll save the key to ~/.ssh/id_ed25519
. If you want to save it
with a different name, specify the file path during the generation process.
Copy the Public Key to the UniFi controller: You need to copy your public key (~/.ssh/id_ed25519.pub
) to the UniFi
controller’s authorized_keys file for SSH access:
`ssh-copy-id -i ~/.ssh/id_ed25519.pub [email protected]`
This will add your public key to the controller's ~/.ssh/authorized_keys
file. If you've completed these steps
successfully, you should be able to ssh into the controller without entering a password. You can test this with the
following command:
`ssh [email protected]`
If you're prompted for a password, something has gone wrong.
You'll need to change the script's variables to match your local environment.
-
HOST="10.0.1.123"
- UniFi controller's IP address -
USER="USERNAME"
- SSH username -
PRIVATE_KEY_PATH="/Users/user/.ssh/id_ed25519"
- Private key path (default: ~/.ssh/id_ed25519) -
BACKUP_FOLDER="/data/autobackup"
- Controller's backup folder -
LOCAL_FOLDER="/path/to/local/folder"
- Local folder to store backups