Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dc911x committed Aug 23, 2019
1 parent d75654e commit c9d234a
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
# UniFi

UniFi scripts and other goodies

#Back-up your UniFi autobackup file

##Before you start

This script makes use of rclone and installs it but you need to manually go through the "rclone config" steps in the setup. There are many different sorts of cloudstorage providers provided in the rclone config. While many use the same settings some require additional steps especially on headless machines.

Please read up on [Rclone][https://rclone.org]

##Rclone config

**TIPS:**

[Rclone][https://rclone.org]
[Configuring rclone on a remote / headless machine][https://rclone.org/remote_setup/]

----------------

Rclone references **"remote:"** a lot, for example to list the top directory of most Cloudprovider you use

`rclone lsd remote:`

To list all the files you use

`rclone ls remote:`

the **"remote"** is actually **the name you choose for your connector** when running rclone config.
So if you name your connector OneDrive it will be

`rclone lsd OneDrive:`

If you name it UniFi-Backup it will be

`rclone lsd UniFi-Backup`

That seems one of the biggest misconceptions from new users when using rclone and reading the docs.

----------------

Want to save your files in another place then the main directory? Just copy the path and add it behind the remote.

`rclone lsd remote:Documents/UniFi/Backup`

Always use `/` even when on Windows.

## Unifi Backup Setup (unifi_backup_setup.sh)

`sudo wget https://raw.githubusercontent.com/dc911x/UniFi/master/unifi_backup_setup.sh -O /usr/local/bin/unifi_backup_setup.sh
sudo chmod +x /usr/local/bin/unifi_backup_setup.sh`

Run the script:

`sudo /usr/local/bin/unifi_backup_setup.sh`

## UniFi Backup (unifi_backup.sh)

After running the setup edit unifi_backup.sh with your favorite editor and add the correct remote from Rclone and path where you want to save the .unf file.

`sudo nano -w /usr/local/bin/unifi_backup.sh`

**That's all folks!**
14 changes: 14 additions & 0 deletions unifi_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# unifi_backup.sh
# UniFi Back-up cron-job
# by Jelle Revyn <https://www.jelle.revyn.xyz/>
# Part of unifi_backup_setup.sh

# Backup directory path
UNIFIBACKUP_DIR=/var/lib/unifi/data/backup/autobackup/
# Rclone directory path
RCLONEBACKUP_DIR=remote:path

#Copy all files that are not older then a day and filter out autobackup.json
rclone --filter "- *.json" --max-age 1d copy ${UNIFIBACKUP_DIR} ${RCLONEBACKUP_DIR}
25 changes: 25 additions & 0 deletions unifi_backup_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# unifi_backup_setup.sh
# UniFi Back-up to cloudprovider using rclone
# by Jelle Revyn <https://www.jelle.revyn.xyz/>
# Version 1.0
# Last Updated 23/08/2019

# Read access to UniFi backup directory
sudo chmod -R 705 /var/lib/unifi/backup/

# Install rclone and go through the process for your cloud provider.
curl https://rclone.org/install.sh | sudo bash

# Configure rclone

rclone config

# Download backupfile
sudo wget https://raw.githubusercontent.com/dc911x/UniFi/master/unifi_backup.sh -O /usr/local/bin/unifi_backup.sh
sudo chmod +x /usr/local/bin/unifi_backup.sh

#Schedule cronjob to run unifi_backup.sh every Sunday at 23u45, please make sure your autobackup is set to sunday BEFORE 23u45 (10min before should be fine)
#Don't forget to edit unifi_backup.sh with the correct settings
sudo crontab -l | { cat; echo "45 23 * * 0 /usr/local/bin/unifi_backup.sh"; } | crontab -

0 comments on commit c9d234a

Please sign in to comment.