Browse Source

add my systemd timers

master
Markus Bergholz 8 months ago
parent
commit
32b61fd317
5 changed files with 137 additions and 0 deletions
  1. +13
    -0
      roles/systemd_timers/tasks/backup.sh
  2. +57
    -0
      roles/systemd_timers/tasks/backup.yml
  3. +10
    -0
      roles/systemd_timers/tasks/main.yml
  4. +2
    -0
      roles/systemd_timers/tasks/nextcloud_cron.sh
  5. +55
    -0
      roles/systemd_timers/tasks/nextcloud_cron.yml

+ 13
- 0
roles/systemd_timers/tasks/backup.sh View File

@@ -0,0 +1,13 @@
#!/bin/bash

echo "mount rw"
sudo mount -o remount,rw /mnt/backup/
echo "dump nextcloud"
mysqldump --single-transaction nextcloud | zstd > /home/m/nextcloud.sql.zst
echo "dump gitea"
mysqldump --single-transaction gitea | zstd > /home/m/gitea.sql.zst
echo "rsnapshot"
sudo rsnapshot daily
echo "mount ro"
sudo mount -o remount,ro /mnt/backup/


+ 57
- 0
roles/systemd_timers/tasks/backup.yml View File

@@ -0,0 +1,57 @@
- name: file nextcloud_cron.sh
copy:
src: backup.sh
dest: /home/m/backup.sh
owner: m
group: m
mode: a+x

- name: delete unit file if exists
file:
state: absent
path: /etc/systemd/system/backup.service

- name: delete timer file if exists
file:
state: absent
path: /etc/systemd/system/backup.timer
- name: backup cron unit file
blockinfile:
create: yes
path: /etc/systemd/system/backup.service
block: |
[Unit]
Description=run daily backup
After=network.target
Requires=docker.service

[Service]
Type=oneshot
User=m
ExecStart=/home/m/backup.sh


- name: backup cron timer file
blockinfile:
create: yes
path: /etc/systemd/system/backup.timer
block: |
[Unit]
Description=run daily backup
After=network.target
Requires=docker.service

[Timer]
OnCalendar=*-*-* 4:00:00
Persistent=true

[Install]
WantedBy=basic.target


- name: enable backup cron job
systemd:
name: backup.timer
state: started
enabled: yes

+ 10
- 0
roles/systemd_timers/tasks/main.yml View File

@@ -0,0 +1,10 @@
---
- name: take care about my systemd timers
become: yes
become_method: sudo

block:
- include_tasks: nextcloud_cron.yml
- include_tasks: backup.yml
...

+ 2
- 0
roles/systemd_timers/tasks/nextcloud_cron.sh View File

@@ -0,0 +1,2 @@
#!/bin/bash
docker exec -u www-data $(docker ps --filter "Name=nextcloud" --format "{{.Names}}") php cron.php

+ 55
- 0
roles/systemd_timers/tasks/nextcloud_cron.yml View File

@@ -0,0 +1,55 @@
- name: file nextcloud_cron.sh
copy:
src: nextcloud_cron.sh
dest: /opt/bin/nextcloud_cron.sh
owner: root
group: root
mode: a+x

- name: delete unit file if exists
file:
state: absent
path: /etc/systemd/system/nextcloud_cron.service

- name: delete timer file if exists
file:
state: absent
path: /etc/systemd/system/nextcloud_cron.timer
- name: nextcloud_cron unit file
blockinfile:
create: yes
path: /etc/systemd/system/nextcloud_cron.service
block: |
[Unit]
Description=run nextcloud cron.php every 15 minutes
After=network.target
Requires=docker.service

[Service]
Type=oneshot
User=m
ExecStart=/opt/bin/nextcloud_cron.sh

- name: nextcloud_cron timer file
blockinfile:
create: yes
path: /etc/systemd/system/nextcloud_cron.timer
block: |
[Unit]
Description=run nextcloud cron.php every 15 minutes
After=network.target
Requires=docker.service

[Timer]
OnCalendar=*:0,15,30,45
Persistent=true

[Install]
WantedBy=basic.target

- name: enable nextcloud cron job
systemd:
name: nextcloud_cron.timer
state: started
enabled: yes

Loading…
Cancel
Save