Skip to content

Commit

Permalink
Add github_backup playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
Vic Shóstak committed Jul 21, 2020
1 parent c356fee commit 66e8bdb
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ansible-playbook <playbook_name>-playbook.yml [args] [extra vars...]
- 📖 [`new_server`](https://github.com/truewebartisans/useful-playbooks/blob/master/docs/new_server.md) for auto configure a fresh remote virtual server
- 📖 [`install_brotli`](https://github.com/truewebartisans/useful-playbooks/blob/master/docs/install_brotli.md) for install Brotli module to Nginx
- 📖 [`create_ssl`](https://github.com/truewebartisans/useful-playbooks/blob/master/docs/create_ssl.md) for create a new website with SSL certificate from Let's Encrypt
- 📖 [`github_backup`](https://github.com/truewebartisans/useful-playbooks/blob/master/docs/github_backup.md) for a backup automation of your GitHub accounts (repositories, gists, organizations)

## 💡 Required information about Ansible

Expand Down Expand Up @@ -87,7 +88,7 @@ For better readability, please add two association to your `.vscode/settings.jso
"files.associations": {
// ...
"*-domain.j*2": "NGINX", // for all jinja2 files ended with `domain` word
"*-playbook.y*ml": "ansible" // for YAML files ended with `playbook` word
"*playbook.y*ml": "ansible" // for YAML files ended with `playbook` word
}
// ...
}
Expand All @@ -97,14 +98,14 @@ For better readability, please add two association to your `.vscode/settings.jso

Since Ansible `v2.5.x`, you can enable beautify output by [callback_plugins](https://docs.ansible.com/ansible/2.5/plugins/callback.html) and auto convert this _one line_ output:

```console
```bash
TASK [Get SSL for domain] *******************************
fatal: [***]: FAILED! => {"changed": true, "cmd": ["certbot", "--nginx", "certonly", "--agree-tos", "-m", "test@example.com", "-d", "example.com", "-d", "www.example.com", "--dry-run"], "delta": "***", "end": "***", "msg": "non-zero return code", "rc": 1, "start": "***", "stderr": "..." ...
```

To awesome structured, like this:

```console
```bash
TASK [Get SSL for domain] *******************************
fatal: [***]: FAILED! => changed=true
cmd:
Expand Down
7 changes: 6 additions & 1 deletion create_ssl-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Ansible playbook for create SSL certificate for your domains (by Let's Encrypt).
# For more information, please visit https://github.com/truewebartisans/useful-playbooks
# Author: Vic Shóstak <truewebartisans@gmail.com> & True web artisans (https://1wa.co)
# License: MIT

---
- hosts: "{{ host }}"
- hosts: "{{ host|default('localhost') }}"
become: true

tasks:
Expand Down
76 changes: 76 additions & 0 deletions docs/github_backup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# [](https://github.com/truewebartisans/useful-playbooks) 📖 `github_backup` playbook

Automate a backup process of your GitHub accounts (repositories, gists, organizations).

## Usage

```bash
ansible-playbook \
github_backup-playbook.yml \
--user <USER> \
--extra-vars "host=<HOST>"
```

### Extra vars

- `<USER>` (**required**) remote user's username (for example, `root`)
- `<HOST>` (**required**) hostname in your inventory (from `/etc/ansible/hosts` file)

> 👌 Yes, actually you can specify the `<USER>` argument in your inventory file (`/etc/ansible/hosts`) and do not place it here. We use the `{{ ansible_user }}` variable in playbook to point to the remote user.
## Additional configuration

Please, create a `.env` file with the following structure (where this playbook is located):

```ini
# GitHub users or organizations login names, separated with commas (without spaces).
USERS=user123,org123

# GitHub personal access token.
# Generate it here: https://github.com/settings/tokens
GITHUB_TOKEN=0000000000000000000000000

# Max count of a saved backup files.
MAX_BACKUPS=10

# Time to delay.
# - d: days
# - h: hours
# - m: minutes
# - s: seconds
DELAY_TIME=1d

# Timezone for DELAY_TIME.
# See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TIME_ZONE=America/Chicago
```

> ☝️ This is required, because the Docker image uses these environment variables.
## Features

- Playbook uses a configured Docker image to create a container ([koddr/github-backup-automation](https://github.com/koddr/github-backup-automation)).
- You can set your own configuration (in `.env` file or inline variables) to:
- Timezone and interval to run the backup process.
- Count of a saved backup archives.
- Backups are compressed with gzip (`tar.gz`).
- Backups are stored in a folder named by date and time of creation.
- Older archives will be removed automatically.

## Tested to work

- All major systems (macOS, Linux, Windows), where installed Docker `19.03.x` (and later).

> 😉 Hey, if you have tested other versions and/or OS, please write [issue](https://github.com/truewebartisans/useful-playbooks/issues/new) or send [pull request](https://github.com/truewebartisans/useful-playbooks/pulls).
## 📺 Media

A list of articles and video lessons, where `github_backup` playbook is used:

- It's empty for now... 😐

> Make [pull request](https://github.com/truewebartisans/useful-playbooks/pulls) with links to your articles and videos! We will post them right here.
<br/>

[← Back to List](https://github.com/truewebartisans/useful-playbooks#-available-playbooks)
18 changes: 18 additions & 0 deletions github_backup-playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Ansible playbook for a backup automation of your GitHub accounts (repositories, gists, organizations).
# For more information, please visit https://github.com/truewebartisans/useful-playbooks
# Author: Vic Shóstak <truewebartisans@gmail.com> & True web artisans (https://1wa.co)
# License: MIT

---
- hosts: "{{ host|default('localhost') }}"

tasks:
- name: Run Docker container for backup your GitHub accounts
docker_container:
name: github-backup-automation
image: koddr/github-backup-automation:latest
recreate: yes
env_file: ${PWD}/.env
volumes:
- ./var/github-backup:/srv/var/github-backup
state: started
7 changes: 6 additions & 1 deletion install_brotli-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Ansible playbook for install Brotli module to exists Nginx on your server.
# For more information, please visit https://github.com/truewebartisans/useful-playbooks
# Author: Vic Shóstak <truewebartisans@gmail.com> & True web artisans (https://1wa.co)
# License: MIT

---
- hosts: "{{ host }}"
- hosts: "{{ host|default('localhost') }}"
become: true

tasks:
Expand Down
7 changes: 6 additions & 1 deletion new_server-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Ansible playbook for create a new server, based on Ubuntu/Debian.
# For more information, please visit https://github.com/truewebartisans/useful-playbooks
# Author: Vic Shóstak <truewebartisans@gmail.com> & True web artisans (https://1wa.co)
# License: MIT

---
- hosts: "{{ host }}"
- hosts: "{{ host|default('localhost') }}"
become: true

tasks:
Expand Down

0 comments on commit 66e8bdb

Please sign in to comment.