| by TheIneptOne | 1 comment

Ubiquiti Unifi Controller Backup

We host our Unifi Controller on Ubuntu and needed a way to back it up to our Windows server (don’t ask).


  • A base install of Ubuntu 20.04 LTS with a static IP address
  • When editing a file with Nano, to save your changes to do the following:
    • Ctrl+X to Exit
    • Y to save the edits currently stored in the buffer
    • Enter to write to the current file name
To backup the installation, we need to do the following:
  • Create a directory and mount a Windows share to that folder
  • Create a simple bash script to copy the auto backups to this mounted share
  • Set a cron job to run that bash script daily
We’ll use the share located on WIN-SERVER1 and a folder called backups in that share. (\\win-server1\shared\backups)
First we’ll need to create a local directory to mout the share
sudo mkdir /media/share

Next, set the permissions for the directory

sudo chown -R nobody:nogroup /media/share && sudo chown -R 0777 /media/share
Now, install CIFS to be able to connect and mount Windows shares
sudo apt update && sudo apt install cifs
We can perminantely mount the Windows share to that directory
sudo nano /etc/fstab

Add the following to the end of the file (note the //ip instead of \\ip. Linux uses forward slashes while Windows uses backslashes)

# Windows share on WIN-SERVER1

//win-server1/shared/backups /media/share cifs username=windowsuser,password=password,uid=nobody,iocharset=utf8,noperm 0 0

Mount the share

sudo mount -a
Create a file to save our script. We’ll keep this in the user home directory
sudo touch backup.sh

Add the following to the script


rsync -av --delete /usr/lib/unifi/data/backup /media/share
Make the script executable
sudo chmod +x backup.sh
 With the script completed, we can create the cron job to run the script everyday
sudo touch /etc/cron.d/unifi-backup
Add the following to the file and save it
# Copies the files from /var/lib/unifi/data/backups to /media/share
# which is a Windows share on WIN-SERVER1. From there, the backup files
# will be backed up via iDrive.
# Ver 1.0 5/27/2021 - IneptTech

0 22 * * * root /home/linuxuser/backup.sh
Once done, press Ctrl+X, then and Enter to save the file. This will run the script everyday at 10PM








1 Comment

Ubiquiti Unifi Controller Setup – Inept Tech

February 15, 2022 at 8:06 pm Reply

[…] That’s it. The controller is now installed and you begin the setup process by going to https://ipaddress:8443. It’s highly recommended that you setup an SSL certification through Lets Encrypt as well as automated backups of the controller. […]

Leave a Reply