Search for previous posts

Blog History


AWS Ubuntu Unifi config backup to S3 via Rclone

There seems to be many strategies online for copying Unifi's .unf backup files off the controller, but I wanted something simple, clean, and lightweight. Here is the solution I decided upon, with the following three requirements:

  1. Not duplicate or overwrite files after they were uploaded
  2. Run everday
  3. Remove files after a certain set of days
The first is solved by Rclone's [1] copy switch, as it only copies "new or changed files to cloud storage". Caveat: the controller has to be running on a Linux host. If you use a Unifi Cloud Key or Windows, your steps will probably be different (Possibly a pull instead of a push).

First is to download and install Rclone on your instance:
curl | sudo bash

Next is the configuration of Rclone. As my controller was running on an EC2 instance, using an IAM instance profile [2] is easiest and best practice, but you can also just create a service user with AWS programmatic credentials. The below command will walk you through options, customize to your preferences. Mine was for AWS S3 [3]:

rclone config

I named my config UnifiBackup. Now make the S3 bucket:

rclone mkdir UnifiBackup:<bucket name>

Now you're ready to run the copy process:

sudo su

rclone copy /usr/lib/unifi/data/backup/autobackup UnifiBackup:<bucket name>

If everything is correctly configured, all your autobackup files should be in your S3 bucket. If so, follow these steps:

- Create a simple one line bash script from the above copy command 

- Modify the script to be executable:
    chmod +x <script name>

- Setup a cronjob [4] to run at your desired schedule. Make sure to edit root's cron schedule, as Ubiquiti has decided to lock down perms to the Unifi backups directory:

    sudo crontab -e


    0 2 * * * /home/ubuntu/<script name>

The third requirement I had was solved by AWS S3 "Object lifecycle" [5]. You set the objects to expire current version of object after __ days from object creation and then permanently delete previous versions after __ days from becoming a previous version.








No comments:

Post a Comment