Ansible role for creating backups with s3cmd
Go to file
Jakub Sokołowski 3356b07065
install s3cmd from apt
Signed-off-by: Jakub Sokołowski <jakub@status.im>
2020-09-29 22:41:08 +02:00
defaults install s3cmd from apt 2020-09-29 22:41:08 +02:00
meta add role metadata 2019-07-31 13:16:36 -04:00
tasks install s3cmd from apt 2020-09-29 22:41:08 +02:00
templates install s3cmd from apt 2020-09-29 22:41:08 +02:00
LICENSE add MIT license 2019-06-05 13:49:31 -04:00
README.md switch to using systemd service and timer instead of cron 2020-01-24 16:36:40 +01:00

README.md

Description

This role is intended for uploading backups to DigitalOcean Spaces using the s3cmd script.

Installation

In your requirements.yml file:

- name: infra-role-s3cmd-backup
  src: git@github.com:status-im/infra-role-s3cmd-backup.git
  scm: git

Usage

This role should be included by anothe role and ran with certain variables:

- name: Configure Ghost backups
  include_role:
    name: s3cmd-backup
  vars:
    backup_name: my-app-backups
    backup_number: 1
    backup_hour: 4
    backup_day: '*/4'
    backup_directory: '/var/tmp/backups'
    backup_base_domain: 'ams3.digitaloceanspaces.com'
    backup_bucket_name: 'my-app-backups'
    backup_access_key: 'ACCESS_KEY'
    backup_secret_key: 'SECRET_KEY'

If you want to use S3 you can set:

backup_base_domain: s3.amazonaws.com

Administration

The upload job runs as a systemd service triggered by a timer. Assuming our backup target is called database you can do:

 $ sudo systemctl status backup-database.service
● backup-database.service - "Service for uploading database backups to s3 buckets."
   Loaded: loaded (/lib/systemd/system/backup-database.service; static; vendor preset: enabled)
   Active: inactive (dead) since Fri 2020-01-24 15:08:57 UTC; 7min ago
     Docs: https://github.com/status-im/infra-role-s3cmd-backup
  Process: 15536 ExecStart=/var/lib/backups/backup_hackmd.sh (code=exited, status=0/SUCCESS)
 Main PID: 15536 (code=exited, status=0/SUCCESS)

Jan 24 15:08:44 node-01.do-ams3.todo.misc systemd[1]: Starting "Service for uploading database backups to s3 buckets."...
Jan 24 15:08:44 node-01.do-ams3.todo.misc backup_database.sh[15536]: Uploading: database_db_dump_20200124040001.sql >> s3://hackmd-backups
...

You can check the timer status too:

 $ sudo systemctl list-timers backup-database.timer
NEXT                         LEFT    LAST PASSED UNIT                  ACTIVATES
Sat 2020-01-25 00:00:00 UTC  8h left n/a  n/a    backup-database.timer backup-database.service