forked from jswetzen/docker-rsync-backup
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rsync_backup.yml
83 lines (72 loc) · 2.37 KB
/
rsync_backup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
#
# Title: rsync_backup docker with automatic upload functionality
# Author(s): MrDoob / doob187 / kkhiller
#
# License: Copyright (c) 2020 @Authors
# Own Risk any edits or mods
################################################################################
---
- hosts: localhost
gather_facts: false
tasks:
# #######################################################################
- name: 'Set Known Facts'
set_fact:
amg_role: 'rsync-backup'
image: 'mrdoob/rsyncbackup'
- name: 'Register TimeZone'
shell: 'cat /etc/timezone'
register: tz
- name: 'Register Server ID'
shell: 'cat /var/plexguide/server.id'
register: serverid
- name: 'Setting {{amg_role}} Volumes'
set_fact:
amg_volumes:
- '/opt/appdata/:/home'
- '/mnt/backup:/backup'
- '/opt/appdata/{{amg_role}}/rclone:/rclone'
- '/opt/appdata/{{amg_role}}/log:/log'
- name: 'Setting {{amg_role}} ENV'
set_fact:
amg_env:
CRON_TIME : '0 1 * * *'
CONTAINER_TIMEZONE: '{{tz.stdout}}'
BACKUP_HOLD: '15'
SERVER_ID: '{{serverid.stdout}}'
## VALUES for upload backups
- name: 'Create {{amg_role}} dir folder'
file:
path: '/opt/appdata/{{amg_role}}/rclone'
state: directory
mode: '0755'
- name: 'Check of Existance files in {{ amg_role }}'
stat:
path: '/opt/appdata/{{amg_role}}/rclone/rclone.conf'
register: rcp
- name: 'Remove old rclone.conf from {{ amg_role }} folder'
shell: 'rm -rf /opt/appdata/{{amg_role}}/rclone/rclone.conf'
ignore_errors: yes
when: rcp.stat.exists == true
- name: 'Clone rclone.config to {{ amg_role }} folder'
shell: 'cp -r /opt/appdata/plexguide/rclone.conf /opt/appdata/{{amg_role}}/rclone/rclone.conf'
ignore_errors: yes
# MAIN DEPLOYMENT
# #############################################################
- name: 'Deploying {{amg_role}}'
docker_container:
name: '{{amg_role}}'
image: '{{image}}'
pull: yes
volumes: '{{amg_volumes}}'
env: '{{amg_env}}'
restart_policy: unless-stopped
capabilities:
- 'SYS_TIME'
- 'SYS_NICE'
networks:
- name: plexguide
aliases:
- 'rsync-backup'
state: started