Code Monkey home page Code Monkey logo

ot-smoothbrain-backup's Introduction

OT-Smoothbrain-Backup

Backup system for OriginTrail Nodes (Also supports Ansible)

This backup system has several advantages over the default OriginTrail backup system. Their system copies 100% of everything it is backing up and sends it to Amazon. Every time. This means if your backup size is 10gig and you run it once a day you will have 70gig in a week. It also doesn't address verification nor does it ever delete old backups off of Amazon on a regular schedule. You can achieve these objectives yourself but most backup systems do this within the program.

What makes this system better is a few things:

  1. It only updates what is new or changed. Files that haven't changed do not need to be resent. This is called "de-duplication" in the backup world. This means it takes up signifcantly less space and there is no penalty for frequent backups and frequent backups need to be occurring.

If you backup once a week on Mondays and on Friday the VPS dies in such a way you're data isn't recoverable you lose all the jobs you won since that last backup. Today that might not amount to much but tomorrow it will. A job is a job. There is no reason to lose a job over data loss. This system, by default, backs up four times a day (12pm/6pm/12am/6am localtime) and is user-changable to whatever you want.

  1. It will, weekly, remove all but the latest "snapshot". A snapshot is a backup of the new or changed files since the previous snapshot/backup. In this process it merges the data from those previous backups so this remaining snapshot contains a full image of the current state of the files.

  2. It then checks the files in the snapshots for consistancy and accuracy.

All of this is messaged to you in Telegram (if the token/chat_id is provided).

So it's significantly improved over the standard backup method.. :)

** BEGIN INSTRUCTIONS **

THIS SYSTEM SUPPORTS MULTIPLE SERVERS ON BOTH ONE AND MULTIPLE BUCKETS. I HIGHLY RECOMMEND USING ONE BUCKET FOR ALL THE SERVERS. THE SYSTEM NATIVELY EXPECTS THAT AND IS DESIGNED TO HANDLE IT WELL AS IT LABELS EACH SNAPSHOT WITH THE HOSTNAME THAT MADE IT. IF YOU CHOOSE TO USE MULTIPLE BUCKETS THEN EACH SERVERS CONFIG HAS TO BE EDITED FOR THE CORRECT S3/B2 BUCKET AND STEP 11 MUST BE RUN ON EACH SERVER.

FOR THOSE INSTALLING ON MULTIPLE SERVERS AND USING ONE BUCKET STEP 11 ONLY NEEDS TO BE INSTALLED ON ONE COMPUTER AND IT DOES NOT HAVE TO BE INSTALLED (BUT CAN BE) ON A SERVER RUNNING A NODE. WHEN THE CLEANUP SCRIPT RUNS IT LOCKS THE SPECIFIC BUCKET. IF TWO SERVERS USING THE SAME BUCKET RUN THE CLEANUP SCRIPT IT WILL CAUSE AN ISSUE AND ALL BUT ONE CLEANUP SCRIPT WILL BE DENYED, GENERATING AN ERROR.

I RENT A LOW-TIER VPS WHICH I USE FOR CONTROL OPERATIONS ON MY NODES. IT DOES HAVE A ORIGINTRAIL NODE AND IS USED TO SERVICE AND MAINTAIN MY NODES. IT IS ON THIS SERVER THE WEEKLY CLEANUP SCRIPT RUNS.

  1. Login as root
  2. cd
  3. git clone https://github.com/calr0x/OT-Smoothbrain-Backup.git
  4. cd Smoothbrain-OT-Backup
  5. nano config.sh

Edit the following items:

Edit the RESTIC_REPOSITORY and RESTIC_PASSWORD lines. Remember, if you are using a different bucket for each node then this file MUST be different on each computer it's being installed on!

S3 format should be: s3:https://s3.amazonaws.com/bucket_name_here
B2 format should be: bucketname:path/to/repo

Edit both S3 lines OR both B2 lines.

AWS_ACCESS_KEY_ID="REPLACE_WITH_AWS_ACCESS_KEY"
AWS_SECRET_ACCESS_KEY="REPLACE_WITH_AWS_SECRET_ACCESS_KEY"

B2_ACCOUNT_ID="REPLACE_WITH_B2_ACCOUNT_ID"
B2_ACCOUNT_KEY="REPLACE_WITH_B2_ACCOUNT_KEY"

  1. ctrl+s (to save)
  2. ctrl+x (to exit nano)
  3. chmod -R +x data/* restic*
  4. RUN THE FOLLOWING COMMAND BELOW DEPENDING ON WHETHER IT'S S3 OR B2:

S3: ./restic -r s3.amazonaws.com/bucket_name_here init

B2: ./restic -r b2:bucketname:path/to/repo init

** ANSIBLE USERS STOP HERE
** nano ansible/ansible-install-restic.yml
** READ THE TOP COMMENTS FOR FURTHER INSTRUCTIONS

  1. (crontab -l 2>/dev/null; echo "0 */6 * * * /root/Smoothbrain-OT-Backup/restic-backup.sh") | crontab -

  2. To run an initial backup immediately:

source config.sh && ./restic-backup.sh

THE LAST COMMAND SCHEDULES A WEEKLY CLEANUP OF THE REPOSITORY TO CLEAR OLD BACKUPS. IT IS NOT RUN ON EVERY COMPUTER. IT MUST BE INSTALLED ON ONLY ONE SERVER AND CAN BE A NODE OR A LINUX SERVER THAT'S NOT RUNNING A NODE.

IF YOU ONLY HAVE 1 NODE THEN RUN THIS COMMAND AND YOU ARE DONE. IF YOU ARE RUNNING MULTIPLE NODES AND EACH NODE HAS ITS OWN BUCKET THEN RUN THIS COMMMAND ON EACH NODE. IF YOU HAVE MULTIPLE NODES AND THE NODES SHARE A BUCKET THEN THIS COMMAND CAN ONLY BE RUN ON ONE NODE. IF YOU RUN THIS COMMAND ON MORE THAN ONE NODE IT WILL CREATE A SITUATION WHERE THE WEEKLY CLEANUP WON'T WORK.

  1. (crontab -l 2>/dev/null; echo "0 12 * * 5 /root/Smoothbrain-OT-Backup/restic-cleanup.sh") | crontab -

Done!

ot-smoothbrain-backup's People

Contributors

calr0x avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.