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:
- Not duplicate or overwrite files after they were uploaded
- Run everday
- Remove files after a certain set of days
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 commandThe 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.
Done.
References:
[2] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html
[5] https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html
No comments:
Post a Comment