From bcf52c7c29986cafcd7789fee2907d2611779ed3 Mon Sep 17 00:00:00 2001 From: Pig Monkey Date: Tue, 11 Jul 2017 20:55:32 -0700 Subject: [PATCH] wrap tarsnapper via backitup The default period is set to daily, so this doesn't change anything for existing users -- except that now we default to only executing on AC power. If existing users want to match the previous behavior they should set `tarsnapper.ac_power` to `false`. --- README.md | 62 +++++++++++-------- group_vars/all | 6 +- roles/tarsnap/files/tarsnapper.service | 9 --- roles/tarsnap/handlers/main.yml | 2 +- roles/tarsnap/tasks/main.yml | 10 +-- roles/tarsnap/templates/tarsnapper.service.j2 | 10 +++ roles/tarsnap/templates/tarsnapper.timer.j2 | 4 +- 7 files changed, 58 insertions(+), 45 deletions(-) delete mode 100644 roles/tarsnap/files/tarsnapper.service create mode 100644 roles/tarsnap/templates/tarsnapper.service.j2 diff --git a/README.md b/README.md index 01b1b33..f9ee730 100644 --- a/README.md +++ b/README.md @@ -207,26 +207,37 @@ and cache directory, users should recover their jobs files from backups after the Tarsnapper install is complete. See the Tarsnapper documentation for more details. -### Scheduling Tarsnap +### Running Tarsnap -A systemd unit file and timer are included for Tarsnapper. The timer is set to -execute Tarsnapper hourly (configurable through the `tarsnapper.timer.schedule` -variable). However, as with `mailsync` this timer is not started or enabled by -default. Instead, the timer is added to `/usr/local/etc/trusted_units`, causing -the NetworkManager trusted unit dispatcher to activate the timer whenever a +A systemd unit file and timer are included for Tarsnapper. Rather than calling +it directly, the systemd unit wraps Tarsnapper with [backitup][22]. + +The timer is set to execute the unit hourly, but backitup will only call +Tarsnapper once within the period defined in the `tarsnapper.period` variable. +This defaults to `DAILY`. This increases the likelyhood of completing daily +backups by checking each hour if the unit has run succesfully on the current +calendar day. + +In addition to the period limitation, backitup defaults to only calling +Tarsnapper when it detects the machine ison AC power. To allow Tarsnapper to +run when on battery, set the `tarsnapper.ac_only` variable to `False`. + +As with `mailsync`, the timer is not started or enabled by default. Instead, +the timer is added to `/usr/local/etc/trusted_units`, causing the +NetworkManager trusted unit dispatcher to activate the timer whenever a connection is established to a trusted network. The timer is stopped whenever the network goes down or a connection is established to an untrusted network. -To have the timer activated at boot, change the `tarsnapper.timer.run_on` -variable from `trusted` to `all`. +To have the timer activated at boot, change the `tarsnapper.run_on` variable +from `trusted` to `all`. -If the `tarsnapper.tarsnap.run_on` variable is set to anything other than -`trusted` or `all`, the timer will never be activated. +If the `tarsnapper.run_on` variable is set to anything other than `trusted` or +`all`, the timer will never be activated. ## Tor -[Tor][22] is installed by default. A systemd service unit for Tor is installed, +[Tor][23] is installed by default. A systemd service unit for Tor is installed, but not enabled or started. instead, the service is added to `/usr/local/etc/trusted_units`, causing the NetworkManager trusted unit dispatcher to activate the service whenever a connection is established to a @@ -241,14 +252,14 @@ configuration. ### parcimonie.sh -[parcimonie.sh][23] is provided to periodically refresh entries in the user's +[parcimonie.sh][24] is provided to periodically refresh entries in the user's GnuPG keyring over the Tor network. The service is added to `/usr/local/etc/trusted_units` and respects the `tor.run_on` variable. ## BitlBee -[BitlBee][24] and [WeeChat][25] are used to provide chat services. A systemd +[BitlBee][25] and [WeeChat][26] are used to provide chat services. A systemd service unit for BitlBee is installed, but not enabled or started by default. Instead, the service is added to `/usr/local/etc/trusted_units`, causing the NetworkManager trusted unit dispatcher to activate the service whenever a @@ -267,7 +278,7 @@ remove the `bitlebee.torify` variable or disable Tor entirely by removing the ## git-annex -[git-annex][26] is installed for file syncing. A systemd service unit for the +[git-annex][27] is installed for file syncing. A systemd service unit for the git-annex assistant is enabled and started by default. To prevent this, remove the `gitannex` variable from the config. @@ -287,7 +298,7 @@ networks. ## PostgreSQL -[PostgreSQL][27] is installed and enabled by default. If the +[PostgreSQL][28] is installed and enabled by default. If the `postgresql.enable` variable is set to anything other than `True` or is not defined, the service will not be started or enabled. @@ -301,8 +312,8 @@ database service inappropriate for production use. ## Himawaripy -[Himawaripy][28] is provided to fetch near-realtime photos of Earth from the -Japanese [Himawari 8][29] weather satellite and set them as the user's desktop +[Himawaripy][29] is provided to fetch near-realtime photos of Earth from the +Japanese [Himawari 8][30] weather satellite and set them as the user's desktop background via feh. This should provide early warning of the presence of any Vogon constructor fleets appearing over the Eastern Hemisphere. @@ -346,11 +357,12 @@ By completely removing the `himawaripy` variable, no related tasks will be run. [19]: https://www.tarsnap.com/ [20]: https://www.tarsnap.com/gettingstarted.html [21]: https://github.com/miracle2k/tarsnapper -[22]: https://www.torproject.org/ -[23]: https://github.com/EtiennePerot/parcimonie.sh -[24]: https://www.bitlbee.org/main.php/news.r.html -[25]: https://weechat.org/ -[26]: https://git-annex.branchable.com/ -[27]: http://www.postgresql.org/ -[28]: https://github.com/boramalper/himawaripy -[29]: https://en.wikipedia.org/wiki/Himawari_8 +[22]: https://github.com/pigmonkey/backitup +[23]: https://www.torproject.org/ +[24]: https://github.com/EtiennePerot/parcimonie.sh +[25]: https://www.bitlbee.org/main.php/news.r.html +[26]: https://weechat.org/ +[27]: https://git-annex.branchable.com/ +[28]: http://www.postgresql.org/ +[29]: https://github.com/boramalper/himawaripy +[30]: https://en.wikipedia.org/wiki/Himawari_8 diff --git a/group_vars/all b/group_vars/all index f3ad43a..9764cd9 100644 --- a/group_vars/all +++ b/group_vars/all @@ -105,9 +105,9 @@ passwordless_sudo: tarsnapper: deltas: 1h 1d 7d 30d 365d - timer: - schedule: daily - run_on: trusted + period: DAILY + ac_only: True + run_on: trusted gitannex: stop_on_untrusted: True diff --git a/roles/tarsnap/files/tarsnapper.service b/roles/tarsnap/files/tarsnapper.service deleted file mode 100644 index 9179272..0000000 --- a/roles/tarsnap/files/tarsnapper.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Tarsnapper Backup Service -After=network.target - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/tarsnapper -c /usr/local/etc/tarsnapper.conf make -StandardOutput=syslog -StandardError=syslog diff --git a/roles/tarsnap/handlers/main.yml b/roles/tarsnap/handlers/main.yml index 2557451..d1cb9aa 100644 --- a/roles/tarsnap/handlers/main.yml +++ b/roles/tarsnap/handlers/main.yml @@ -1,4 +1,4 @@ --- - name: restart tarsnapper service: name=tarsnapper.timer state=restarted - when: tarsnapper.timer.run_on == "all" + when: tarsnapper.run_on == "all" diff --git a/roles/tarsnap/tasks/main.yml b/roles/tarsnap/tasks/main.yml index 90e3359..55b7ae1 100644 --- a/roles/tarsnap/tasks/main.yml +++ b/roles/tarsnap/tasks/main.yml @@ -30,7 +30,7 @@ template: src=tarsnapper.conf.j2 dest=/usr/local/etc/tarsnapper.conf - name: Push Tarsnapper service file - copy: src=tarsnapper.service dest=/etc/systemd/system/tarsnapper.service + template: src=tarsnapper.service.j2 dest=/etc/systemd/system/tarsnapper.service notify: - reload systemd config @@ -42,20 +42,20 @@ - name: Enable and start Tarsnapper timer service: name=tarsnapper.timer enabled=yes state=started - when: tarsnapper.timer.run_on == "all" + when: tarsnapper.run_on == "all" - name: Remove Tarsnapper from trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=absent line=tarsnapper.timer - when: tarsnapper.timer.run_on == "all" + when: tarsnapper.run_on == "all" - name: Disable Tarsnapper timer service: name=tarsnapper.timer enabled=no - when: tarsnapper.timer.run_on == "trusted" + when: tarsnapper.run_on == "trusted" - name: Add Tarsnapper to trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=present line=tarsnapper.timer - when: tarsnapper.timer.run_on == "trusted" + when: tarsnapper.run_on == "trusted" diff --git a/roles/tarsnap/templates/tarsnapper.service.j2 b/roles/tarsnap/templates/tarsnapper.service.j2 new file mode 100644 index 0000000..0b7cf4c --- /dev/null +++ b/roles/tarsnap/templates/tarsnapper.service.j2 @@ -0,0 +1,10 @@ +# {{ ansible_managed }} +[Unit] +Description=Tarsnapper Backup Service +After=network.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/backitup {% if tarsnapper.ac_only %}-a {% endif %}-p {{ tarsnapper.period }} -l /usr/local/etc/tarsnapper.lastrun -b "/usr/local/bin/tarsnapper -c /usr/local/etc/tarsnapper.conf make" +StandardOutput=syslog +StandardError=syslog diff --git a/roles/tarsnap/templates/tarsnapper.timer.j2 b/roles/tarsnap/templates/tarsnapper.timer.j2 index 35a17c9..a67fae1 100644 --- a/roles/tarsnap/templates/tarsnapper.timer.j2 +++ b/roles/tarsnap/templates/tarsnapper.timer.j2 @@ -1,10 +1,10 @@ # {{ ansible_managed }} [Unit] -Description=Tarsnapper Synchronization Timer +Description=Tarsnapper Backup Service Timer [Timer] Unit=tarsnapper.service -OnCalendar={{ tarsnapper.timer.schedule }} +OnCalendar=hourly Persistent=True [Install]