diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..a6aa912 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,43 @@ +# Explanation of this file +# https://help.github.com/articles/about-codeowners/ + +* @aessing + +############################################################################### +# This is a comment. +# Each line is a file pattern followed by one or more owners. + +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# @global-owner1 and @global-owner2 will be requested for +# review when someone opens a pull request. +#* @global-owner1 @global-owner2 + +# Order is important; the last matching pattern takes the most +# precedence. When someone opens a pull request that only +# modifies JS files, only @js-owner and not the global +# owner(s) will be requested for a review. +#*.js @js-owner + +# You can also use email addresses if you prefer. They'll be +# used to look up users just like we do for commit author +# emails. +#*.go docs@example.com + +# In this example, @doctocat owns any files in the build/logs +# directory at the root of the repository and any of its +# subdirectories. +#/build/logs/ @doctocat + +# The `docs/*` pattern will match files like +# `docs/getting-started.md` but not further nested files like +# `docs/build-app/troubleshooting.md`. +#docs/* docs@example.com + +# In this example, @octocat owns any file in an apps directory +# anywhere in your repository. +#apps/ @octocat + +# In this example, @doctocat owns any file in the `/docs` +# directory in the root of your repository. +#/docs/ @doctocat diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..7c53912 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: aessing diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..870779e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,46 @@ +--- +name: Bug report +about: Create a report to help to improve the project +title: '' +labels: 'bug' +assignees: '' +--- + + + +## Description + + +## Expected Behavior + + +## Actual Behavior + + +## Context + + +## Possible Fix + + +## Steps to Reproduce + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +## Your Environment + +- Version used: +- Environment name and version (e.g. Chrome 39, node.js 5.4): +- Operating System and version +- Desktop or mobile: +- Hardware used: +- etc. + +## Screenshots + + +## Additional context + \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..ec4bb38 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/critical_bug_report.md b/.github/ISSUE_TEMPLATE/critical_bug_report.md new file mode 100644 index 0000000..6eae6b5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/critical_bug_report.md @@ -0,0 +1,46 @@ +--- +name: Critical bug report +about: Create a report for a critical issue +title: '' +labels: 'bug, critical' +assignees: '' +--- + + + +## Description + + +## Expected Behavior + + +## Actual Behavior + + +## Context + + +## Possible Fix + + +## Steps to Reproduce + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +## Your Environment + +- Version used: +- Environment name and version (e.g. Chrome 39, node.js 5.4): +- Operating System and version +- Desktop or mobile: +- Hardware used: +- etc. + +## Screenshots + + +## Additional context + \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/documentation_issue.md b/.github/ISSUE_TEMPLATE/documentation_issue.md new file mode 100644 index 0000000..4f171bd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation_issue.md @@ -0,0 +1,33 @@ +--- +name: Documentation issue +about: Report issues in the documentation +title: '' +labels: 'documentation' +assignees: '' +--- + + + +## URL to the Article + + +## Description + + +## Expected Documentation + + +## Actual Documentation + + +## Context + + +## Possible Fix + + +## Screenshots + + +## Additional context + \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..dde9bf4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'feature' +assignees: '' +--- + + + +## Detailed Description + + +## Context + + +## Possible Implementation + + +## Describe Alternatives + + +## Additional context + \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 0000000..c0e687e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,9 @@ +--- +name: Question +about: You have a question about the project? +title: '' +labels: 'question' +assignees: '' +--- + + \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..ab84836 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,60 @@ + + +# Pull Request +Thank you for your contribution. + +Before submitting this Pull Request, please make sure: _Put an `x` in the boxes that apply_ +- [ ] You reviewed our [guidelines for contributing](../CONTRIBUTING.md) to this repository +- [ ] Does an issue exists which is related to this Pull Request +- [ ] Your code builds clean without any errors or warnings +- [ ] You are using approved terminology +- [ ] You have added necessary documentation (if appropriate) +- [ ] You have added unit tests + +## Proposed changes + + +## Types of changes +What types of changes does your change introduce? _Put an `x` in the boxes that apply_ +- [ ] New feature (adds functionality) +- [ ] Bugfix (fixes an issue) +- [ ] Security (fixes an security issue) | Please have a look at our [Security Policy](../SECURITY.md) first. +- [ ] Code style cleaning or Refactoring (formatting, renaming, restructuring, etc.) +- [ ] Documentation Update +- [ ] Other (please describe): + +## Breaking change +Does this Pull Request cause existing functionality to not work as expected or even break. _Put an `x` in the boxes that apply_ +- [ ] Yes +- [ ] No + +## Solution Description + + +## How has this been tested? + + +## Deploy Notes + + +## Impacted Areas + +- Area 1 +- Area 2 +- ... + +## Related Issues + +Issue Name | Issue Number +------------------| ---------------------------- +FIRST ISSUE NAME | [#1](/user/project/issues/1) +SECOND ISSUE NAME | [#2](/user/project/issues/2) +... | ... + +## Related Pull Requests + +Branch | Pull Request +----------------------| -------------------------- +ft-NNN-NAME-TRACKERID | [#1](/user/project/pull/1) +bg-NNN-NAME-TRACKERID | [#2](/user/project/pull/2) +... | ... \ No newline at end of file diff --git a/.media/UCK-G2-PLUS.png b/.media/UCK-G2-PLUS.png new file mode 100644 index 0000000..fceb3ec Binary files /dev/null and b/.media/UCK-G2-PLUS.png differ diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..99b5d77 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,48 @@ +# :cop: Code of Conduct + +This Code of Conduct outlines expectations for participation in the community, as well as steps for reporting unacceptable behavior. We are committed to providing a welcoming and inspiring community for all. People violating this code of conduct may be banned from the community. + +This community strive to: + +- __Be friendly and patient__: Remember you might not be communicating in someone else's primary spoken or programming language, and others may not have your level of understanding. +- __Be welcoming__: This community welcomes and support people of all backgrounds and identities. This includes, but is not limited to members of any race, ethnicity, culture, national origin, color, immigration status, social and economic class, educational level, level of experience, sex, sexual identity and orientation, gender identity and expression, personal appearance, age, size, family status, political belief, religion, and mental and physical ability. +- __Be respectful__: This is a world-wide community of professionals, and we conduct ourselves professionally. Disagreement is no excuse for poor behavior and poor manners. Disrespectful and unacceptable behavior includes, but is not limited to: + - Violent threats or language. + - Discriminatory or derogatory jokes and language. + - Posting sexually explicit or violent material. + - Posting, or threatening to post, peoples personally identifying information ("doxing"). + - Insults, especially those using discriminatory terms or slurs. + - Behavior that could be perceived as sexual attention. + - Trolling. + - Other conduct which could reasonably be considered inappropriate in a professional setting. + - Advocating for or encouraging any of the above behaviors. +- __Understand disagreements__: Disagreements, both social and technical, are useful learning opportunities. Seek to understand the other viewpoints and resolve differences constructively. +- This code is not exhaustive or complete. It serves to capture the common understanding of a productive, collaborative environment. We expect the code to be followed in spirit as much as in the letter. + +## :telescope: Scope + +This code of conduct applies to all repos and communities for our projects regardless of whether or not the repo explicitly calls out its use of this code. The code also applies in public spaces when an individual is representing a project or its community. Examples include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## :man_in_tuxedo: Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## :mega: Reporting Code of Conduct Issues + +Whenever possible, the community should try to resolve issues on their own. This builds a broader and deeper understanding and ultimately a healthier interaction. In the event that an issue cannot be resolved locally, please feel free to report your concerns by contacting [codeofconduct@essing.org](mailto:codeofconduct@essing.org). + +In your report please include: +- Your contact information. +- Names (real, usernames or pseudonyms) of any individuals involved. If there are additional witnesses, please include them as well. +- Your account of what occurred, and if you believe the incident is ongoing. If there is a publicly available record (e.g. a mailing list archive or a public chat log), please include a link or attachment. +- Any additional information that may be helpful. + +All reports will be reviewed and will result in a response that is deemed necessary and appropriate to the circumstances. Where additional perspectives are needed, we may seek insights from others with relevant expertise or experience. The confidentiality of the person reporting the incident will always be kept. + +Anyone asked to stop unacceptable behavior is expected to comply immediately. If an individual engages in unacceptable behavior, we may take any action we deem appropriate, including a permanent ban from the community. + +## :receipt: Attribution + +This code of conduct is based on the template established by the [TODO Group](http://todogroup.org/) and used by numerous other large communities (e.g., [Microsoft](https://opensource.microsoft.com/codeofconduct/), [Facebook](https://code.facebook.com/pages/876921332402685/open-source-code-of-conduct), Twitter, GitHub and the Scope section from the [Contributor Covenant version 1.4](http://contributor-covenant.org/version/1/4/). \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..1cea94b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,69 @@ +# :construction_worker: Contributor's Guide + +Below is the guidance for how to report issues, propose new features, and submit contributions via Pull Requests. + +## :beetle: Before you start, file an issue + +Please follow this simple rule to help us stop any unnecessary effort and frustration, so we all can ensure an efficient and effective use of everyone's time - yours, ours, and the time of other community members. + +> If you have a question, or do you think you have discovered an issue, or would you like to propose a new feature, etc., then find/file an issue before starting work to fix or implement it. +> +>:exclamation: **For security issues please have a look at the [Security Policy](SECURITY.md)** :exclamation: + +### :mag_right: Search existing issues first + +Before filing a new issue, search existing open and closed issues first. Perhaps someone else has found the problem you are seeing, and someone may be working on or have already contributed a fix. + +If no existing item describes your issue/feature, great - please file a new issue. + +### :keyboard: File a new Issue + +- You found a security issue and you want to report it? Please have a look at the [Security Policy](SECURITY.md). +- You have found a bug and you want to report it? Please file an issue with the tag "bug". +- You have found something critical, perhaps a bug where data can be lost, etc.? Please file an issue with the tag "critical". +- You got a great idea for a new feature? Please file an issue with the tag "feature". +- You have a question that you do not see answered in docs, videos, etc.? Please file an issue with the tag "documentation". +- You found an existing issue that describes yours? Great - please upvote and add additional commentary / info / repro-steps / etc. + +### :pencil: Complete the template + +Please include as much information as possible in your issue. The more information you provide, the more likely your issue/ask will be understood, accepted, and implemented. + +- Do not assume somebody other than you is an expert in setting up your environment and do not assume somebody else is an expert in your workflow. Please tell us as much details you can, so we can help you as good as possible! +- What steps are needed to reproduce the issue? Assume we love to read repro steps. As much detail as you can stand is probably barely enough detail for us. +- We prefer error message text where possible, or screenshots of errors if the error text cannot be captured. +- If you intend to implement the fix/feature yourself, please say so! If you do not indicate you want to contribute, we assume that the issue is our to solve. + +### :+1: Do not post "+1" comments + +> Please do not post "+1", "me too", or similar comments - these comments just add noise to an issue. + +If you do not have any additional information to add but would like to indicate that you are affected by the issue, upvote the original issue by clicking its :smiley:-button and hitting :+1: (+1) icon. This way it is much easier to measure how impactful an issue is. + +--- + +## :man_technologist: Development + +### :toolbox: Fork, Clone, Branch and Create your PR + +Once you have filed an issue and discussed your proposed feature/fix, it is time to start development: + +1. Fork the repo if you have not already +2. Clone your fork locally +3. Create & push a feature branch +4. Create a [Draft Pull Request](https://github.blog/2019-02-14-introducing-draft-pull-requests/) +5. Work on your changes + +### :eyeglasses: Code Review + +When you would like the project team to take a look, (even if the work is not yet fully-complete), mark the Pull Request as 'Ready For Review' so that the team can review your work and provide comments, suggestions, and request changes. We would like to encourage you to use the Pull Request as tool to start a conversation around your ideas and recruit people to help if necessary. It may take several cycles, but the result will be solid, testable, conformant code that is safe to merge. + +### :jigsaw: Merge + +Once your code has been reviewed and approved, it will be merged. Once merged, your Pull Request will be automatically closed. + +--- + +## :balloon: Thank you + +Thank you in advance for your contribution! \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3939684 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Andre Essing + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0398c25 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# Ubiquiti Unifi Cloud Key Gen 2 Backup to FTP + +![Picture of a Ubiquiti Unifi Cloud Key Gen 2 Plus](.media/UCK-G2-PLUS.png) + +With the latest Firmware Update (>2.0) of the Ubiquiti Cloud Key Generation 2, Ubiquiti stopped using the SD-Card as backup location for automatic backups. Otherwise the new firmware release is doing backups to the local HDD (at Cloud Key Gen 2 Plus), which is harder to access on a hardware error or a general failure. + +For security reasons, enabling SSH on the Cloud Key all the time and pull the backups from the Cloud Key was not an option for me, as SSH on the Coud Key is not restricted by a firewall or public key authentication. So, SSH could be accessed by any device on the network by just using password authentication. + +Pushing backups was the only option. For that, I built this shell script, which sets up everything you need, copies the backups to an external FTP server on your network or the internet. The script uses and configures CRON on the Cloudkey to run every hour. + +:exclamation: As a firmware update resets the changes, you have to manually run the script once after every firmware upgrade. + +> If you have a Unified Dream Machine, have a look at my FTP backup for Ubiquiti Dream Machine using a Docker container. [aessing/udm-backup-ftp](https://github.com/aessing/udm-backup-ftp) + +## Steps to get up and running + +1. Customize the [uck-backup-ftp.sh](uck-backup-ftp.sh) script and copy it over to your Cloud Key Gen 2. I recommend to copy the script to the `/srv` directory. + + * In the scirpt are 4 variables, which are used by the script to logon to the FTP server and copy over the backups. + ```shell + FTP_SERVER={SERVERNAME} + FTP_PATH={BACKUPPATH} + FTP_USER={FTPUSER} + FTP_PASSWORD={FTPPASSWORD} + ``` + + * To copy the script, you have to enable SSH on the Cloud Key (don't forget to deactivate it after you finished) and use scp or a tool of your choice to copy over the script. + ```shell + scp uck-backup-ftp.sh root@[CLOUD_KEY_IP]:/srv + ``` + +1. Login to the Cloud Key via SSH and set the right permissions to the script so it can be executed. + ```shell + chown root.root /srv/uck-backup-ftp.sh + chmod 500 /srv/uck-backup-ftp.sh + ``` + +1. Last but not least, you have to run the script manually once to set everything up. +During the first run, it will + * set up a directory which will be mirrored to the FTP server + * install a FTP client ([_LFTP_](https://github.com/lavv17/lftp)) + * sets up the cron job + * mirrors the backups to the FTP for the first time + ```shell + cd /srv + ./uck-backup-ftp.sh + ``` + +--- + +## :ambulance: Support Information + +For further information about this project, how to [contribute](CONTRIBUTING.md), or how to contact us, please have a look at the [support document](SUPPORT.md) of this repository. It also contains information about [security related topics](SECURITY.md), [licensing](LICENSE.md), and more. + +## :man_judge: Disclaimer + +THE CONTENT OF THIS REPOSITORY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE CONTENT OF THIS REPOSITORY OR THE USE OR OTHER DEALINGS BY CONTENT OF THIS REPOSITORY. \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..c58c070 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,29 @@ +# :detective: Security Policy + +We take the security of our software and services serious, which includes all of our repositories. + +If you believe you have found a security vulnerability in any of our repositories, please report it as described below. + +## :mega: Reporting Security Issues + +__Please do not report security vulnerabilities through public GitHub issues.__ + +Instead, please report them directly via mail to our [Security Team](mailto:codesec@essing.org). + +You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. + +Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: + +- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, credentials stored in code, etc.) +- Full paths of source file(s) related to the manifestation of the issue +- The location of the affected source code (tag/branch/commit or direct URL) +- Any special configuration required to reproduce the issue +- Step-by-step instructions to reproduce the issue +- Proof-of-concept or exploit code (if possible) +- Impact of the issue, including how an attacker might exploit the issue + +This information will help us to understand your report more quickly. + +## :white_flag: Preferred Languages + +We prefer all communications to be in English. \ No newline at end of file diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..2093afd --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,22 @@ +# Support Information + +## :cop: Code of conduct + +Our [Code of Conduct](CODE_OF_CONDUCT.md) outlines expectations for participation in the community, as well as steps for reporting unacceptable behavior. We are committed to provide a welcoming and inspiring community for all. People violating this code of conduct may be banned from the community. + +For more information, or any additional questions or comments, please contact us at [codeofconduct@essing.org](mailto:codeofconduct@essing.org) + +## :construction_worker: Contributor's Guide + +In our [Contributor's Guide](CONTRIBUTING.md) you can find some guidance for how to report issues, propose new features, and submit contributions via Pull Requests. Please read it, before you start working. + +## :scroll: License + +You can find the license information for this repository in its [license](LICENSE.md) file. + +## :detective: Security Policy + +We take the security of our software and services serious, which includes all of our repositories. +If you believe you have found a security vulnerability in any of our repositories, please report it as described in our [Security Policy](SECURITY.md). + +For more information, or any additional questions or comments, please contact us at [codesec@essing.org](mailto:codesec@essing.org) \ No newline at end of file diff --git a/uck-backup-ftp.sh b/uck-backup-ftp.sh new file mode 100644 index 0000000..41020f5 --- /dev/null +++ b/uck-backup-ftp.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +# ============================================================================= +# Unifi Cloud Key Backup to FTP +# https://github.com/aessing/uck-backup-ftp +# ----------------------------------------------------------------------------- +# Developer.......: Andre Essing (https://www.andre-essing.de/) +# (https://github.com/aessing) +# (https://twitter.com/aessing) +# (https://www.linkedin.com/in/aessing/) +# ----------------------------------------------------------------------------- +# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. +# ============================================================================= + +FTP_SERVER={SERVERNAME} +FTP_PATH={BACKUPPATH} +FTP_USER={FTPUSER} +FTP_PASSWORD={FTPPASSWORD} + +############################################################################### +############### Magic Line - Normally no changes below necessary ############## +############################################################################### + +echo "" +echo "=============================================================================" +echo "$(date)" +echo "Starting backtup to:" +echo " - FTP Server: ${FTP_SERVER}" +echo " - FTP Path: ${FTP_PATH}" +echo " - FTP User: ${FTP_USER}" +echo "-----------------------------------------------------------------------------" + +############################################################################### +# +# Setup some stuff +# +echo "" +echo " - Setup some stuff" +BACKUP_ROOT=/uck-backup-ftp +CRON_FILE=/etc/cron.d/uck-backup-ftp +PROTECT_BACKUP_FOLDER=/srv/unifi-protect/backups +PROTECT_BACKUP_LINK=$BACKUP_ROOT/protect +SCRIPT_FILE=`basename $0` +SCRIPT_PATH=$(dirname $(readlink -f $0)) +UNIFI_BACKUP_FOLDER=/srv/unifi/data/backup/autobackup +UNIFI_BACKUP_LINK=$BACKUP_ROOT/unifi + +############################################################################### +# +# Install lftp +# +dpkg -s lftp >/dev/null 2>&1 +if [ ! $? -eq 0 ]; then + echo "" + echo " - Installing lftp with apt-get" + apt-get update + apt-get install --no-install-recommends -y lftp +fi + +############################################################################### +# +# Create backup folder +# +if [ ! -d $BACKUP_ROOT ]; then + echo "" + echo " - Creating backup folder ($BACKUP_ROOT)" + mkdir -p $BACKUP_ROOT +fi +if [ ! -L $UNIFI_BACKUP_LINK ]; then + echo "" + echo " - Linking UNIFI backups ($UNIFI_BACKUP_FOLDER) to backup folder ($UNIFI_BACKUP_LINK)" + ln -s $UNIFI_BACKUP_FOLDER $UNIFI_BACKUP_LINK +fi +if [ ! -L $PROTECT_BACKUP_LINK ]; then + echo "" + echo " - Linking UNIFI backups ($PROTECT_BACKUP_FOLDER) to backup folder ($PROTECT_BACKUP_LINK)" + ln -s $PROTECT_BACKUP_FOLDER $PROTECT_BACKUP_LINK +fi + +############################################################################### +# +# Create CRON file +# +if [ ! -f "$CRON_FILE" ]; then + echo "" + echo " - Setting up CRON job that runs every hour ($CRON_FILE)" + echo "30 * * * * root $SCRIPT_PATH/$SCRIPT_FILE" > $CRON_FILE + chmod 644 $CRON_FILE + systemctl restart cron.service +fi + +############################################################################### +# +# Copy backup files to FTP server +# +echo "" +echo " - Copy backups to FTP server ($FTP_SERVER)" +/usr/bin/lftp -e "set ssl:verify-certificate no;mirror --overwrite --no-perms --no-umask -RL $BACKUP_ROOT $FTP_PATH;exit" -u $FTP_USER,$FTP_PASSWORD $FTP_SERVER +echo "" +echo " - done" +echo "" +echo "=============================================================================" +echo "" + +############################################################################### +#EOF \ No newline at end of file