Git Product home page Git Product logo

backup-action's Introduction

๐Ÿ—„๏ธ backup-action

GitHub Action for backing up DB & Directories.

First of all, Thanks ๐Ÿ™ to @appleboy for drone-ssh & ssh-action to make this happen.

Heads up !! Notes

This action backups the things and store it to /github/workspace/backups folder inside the container. You can attach several actions available at the Marketplace and store this backup to your choice of location.

Pre Requisites

Example Usecase

name: backup db
on:
  schedule:
    - cron: "0 10 * * 1" # Every Monday at 10 AM UTC
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: Backup MySQL DB
      uses: valerianpereira/backup-action@master
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        password: ${{ secrets.PASSWORD }}
        port: ${{ secrets.PORT }}
        key: ${{ secrets.DEPLOY_KEY }}
        type: db
        db_type: mysql
        db_user: ${{ secrets.MYSQL_USER }}
        db_pass: ${{ secrets.MYSQL_PASS }}
        db_port: 3306
        db_name: world

output:

DB type: mysql
๐Ÿƒโ€โ™‚๏ธ Running commands over ssh...
======CMD======
mysqldump -q -u *** -P 3306 -p'***' world | gzip -9 > mysql-world.1109201613.sql.gz
======END======
err: mysqldump: [Warning] Using a password on the command line interface can be insecure.
==============================================
โœ… Successfully executed commands to all host.
==============================================
๐Ÿ”‘ Loading the deploy key...
Done!! ๐Ÿป
๐Ÿ”„ Sync the mysql backups... ๐Ÿ—„
Warning: Permanently added '***' (ECDSA) to the list of known hosts.
receiving incremental file list
mysql-world.1109201613.sql.gz
              0   0%    0.00kB/s    0:00:00  
        623.78K  18%  605.53kB/s    0:00:04  
          3.45M 100%    2.32MB/s    0:00:01 (xfr#1, to-chk=0/1)
sent 51 bytes  received 3.46M bytes  628.39K bytes/sec
total size is 3.45M  speedup is 1.00
๐Ÿค” Whats the location of backups...
/github/workspace/backups
๐Ÿ” Show me backups... ๐Ÿ˜Ž
total 3M     
-rw-r--r--    1 ***     ***        3.3M Sep 11 16:14 mysql-world.1109201613.sql.gz

More Examples with Additional Attachments:

TIP: You can refer to ci.yml for more understanding.

Input variables

See action.yml for more detailed information.

  • host - ssh host
  • port - ssh port, default is 22
  • username - ssh username
  • password - ssh password
  • passphrase - the passphrase is usually to encrypt the private key
  • sync - synchronous execution if multiple hosts, default is false
  • timeout - timeout for ssh to remote host, default is 30s
  • command_timeout - timeout for ssh command, default is 10m
  • key - content of ssh private key. ex raw content of ~/.ssh/id_rsa
  • key_path - path of ssh private key
  • fingerprint - fingerprint SHA256 of the host public key, default is to skip verification
  • script - execute commands
  • script_stop - stop script after first failure
  • envs - pass environment variable to shell script
  • debug - enable debug mode
  • use_insecure_cipher - include more ciphers with use_insecure_cipher (see #56)
  • cipher - the allowed cipher algorithms. If unspecified then a sensible

Backup Config:

  • type: type of backup to be triggered (directory or db) required
  • db_type: type of database eg: mongo / postgres / mysql
  • db_user: database username required
  • db_pass: database password (optional)
  • db_name: database name required
  • db_host: database host default: localhost
  • db_port: database port
  • auth_db: authenticationDatabase Required for Mongo DB v4.4.0 default: admin
  • args: additional arguments with backup command if you want to pass optional
  • dirpath: directory path to be backuped required when type is set to directory

SSH Proxy Setting:

  • proxy_host - proxy host
  • proxy_port - proxy port, default is 22
  • proxy_username - proxy username
  • proxy_password - proxy password
  • proxy_passphrase - the passphrase is usually to encrypt the private key
  • proxy_timeout - timeout for ssh to proxy host, default is 30s
  • proxy_key - content of ssh proxy private key.
  • proxy_key_path - path of ssh proxy private key
  • proxy_fingerprint - fingerprint SHA256 of the proxy host public key, default is to skip verification
  • proxy_use_insecure_cipher - include more ciphers with use_insecure_cipher (see #56)
  • proxy_cipher - the allowed cipher algorithms. If unspecified then a sensible

Setting up SSH Key

Login to Remote Server

Make sure to follow the below steps while creating SSH Keys and using them. Login with username specified in Github Secrets. Generate a RSA Key-Pair:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Add newly generated key into Authorized keys. Read more about authorized keys here.

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Copy Private Key content and paste in Github Secrets.

clip < ~/.ssh/id_rsa

See the detail information about SSH login without password

Disclaimer

  • Check your keys.
  • Check your custom scripts properly.
  • Pass all credentials from Github Secrets.
  • Pass DB Credentials with Read-only access to database.
  • Use it at your own risk! ๐Ÿ™

Roadmap

  • Add Backup & Restore Commands Explanations to ReadME
  • Features to generate Backup Reports and Store it in txt file.

Contributions

If you've ever wanted to contribute to open source, and a great cause, now is your chance!

Suggestions, Feedbacks, Improvements & Fixes are most welcome. ๐Ÿ™

Follow Us

That's all Folks. Enjoy.

backup-action's People

Contributors

dr5hn avatar valerianpereira avatar valerian-pereira avatar jskz avatar jackton1 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.