Backup - Action
Tags: actionshackathon
Published: 2020-09-14 14:42:43

<p align="center">
    <img src="https://raw.githubusercontent.com/valerianpereira/backup-action/master/images/backup.svg" width="200">
</p>

[GitHub Action](https://github.com/features/actions) for backing up DB & Directories at regular intervals.

### Uses
{% github appleboy/drone-ssh no-readme %}

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon, please fill out all sections.)

## 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](https://github.com/marketplace?type=actions) and store this backup to your choice of location.

## Pre Requisites
- SSH Key Access to Remote Server. [How to setup?](https://github.com/valerianpereira/backup-action#setup-ssh-key)

### My Workflow / Example Usage
[Note]: # (Make sure to include the name of your GitHub Action and share where it's being used!)

Action Name: [Backup-Action](https://github.com/marketplace/actions/backup-action)

*Feel free to contribute.*

```yaml
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:

```sh
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
```

### Submission Category: 
Maintainer Must-Haves

### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)

{% github valerianpereira/backup-action %}

### Additional Resources / Info / Usecases

[Note]: # (Be sure to link to any open source projects that are using your workflow!)

* [Backup & Push to S3](https://github.com/valerianpereira/backup-action/blob/master/examples/backup-postgres-push-to-s3.yml)
* [Backup & Push to Server via Rsync](https://github.com/valerianpereira/backup-action/blob/master/examples/backup-mongo-push-to-server-rsync.yml)
* [Backup & Push to Server via SCP](https://github.com/valerianpereira/backup-action/blob/master/examples/backup-mongo-push-to-server-scp.yml)
* [Backup & Push to Artifacts](https://github.com/valerianpereira/backup-action/blob/master/examples/backup-mysql-push-to-email.yml)
* [Backup & Push to Github](https://github.com/valerianpereira/backup-action/blob/master/examples/backup-postgres-push-to-s3.yml)

[Note]: # (Be sure to include the DEV usernames of your collaborators, if any. )

### Collaborators
{% user valerianpereira %}
{% user dr5hn %}

[Reminder]: # (Submissions are due on September 17th (11:59 PM PDT) and winners will be announced on September 23!)