From f7983691ab7454c895bcf5be5988be269f8eadb3 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 20 Mar 2015 01:11:13 +0100 Subject: backup-var-log: Adding first version of backup-var-log script, service and timer. --- scripts/backup-var-log | 26 ++++++++++++++++++++++++++ system/backup-var-log.service | 11 +++++++++++ system/backup-var-log.timer | 10 ++++++++++ 3 files changed, 47 insertions(+) create mode 100755 scripts/backup-var-log create mode 100644 system/backup-var-log.service create mode 100644 system/backup-var-log.timer diff --git a/scripts/backup-var-log b/scripts/backup-var-log new file mode 100755 index 0000000..88babe8 --- /dev/null +++ b/scripts/backup-var-log @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +timestamp="$(date +"%Y%m%d-%H%M%S")-" + +# If the backup location doesn't exist yet, create it +if [ ! -d $var_log_folder_destination ]; then + mkdir -p $var_log_folder_destination +fi + +if [ -d $var_log_parent_source ]; then + cd $var_log_parent_source +else + exit 1 +fi + +echo "$var_log_folder_source -> $var_log_folder_destination$timestamp$var_log_folder_source$tar_suffix$gpg_suffix" +# tar in /tmp +tar cfJ $tmp$timestamp$var_log_folder_source$tar_suffix $var_log_folder_source --exclude='journal' +# gpg to var_log_folder_destination +gpg -e \ + -r "$gpg_public_key" \ + -o $var_log_folder_destination$timestamp$var_log_folder_source$tar_suffix$gpg_suffix \ + $tmp$timestamp$var_log_folder_source$tar_suffix +# delete tar in /tmp +rm -f $tmp$timestamp$var_log_folder_source$tar_suffix + diff --git a/system/backup-var-log.service b/system/backup-var-log.service new file mode 100644 index 0000000..6c9fc79 --- /dev/null +++ b/system/backup-var-log.service @@ -0,0 +1,11 @@ +[Unit] +Description=Backup /var/log directory +ConditionFileIsExecutable=/usr/lib/systemd/scripts/backup-var-log + +[Service] +EnvironmentFile=/etc/backup-settings +Nice=19 +IOSchedulingClass=2 +IOSchedulingPriority=7 +ExecStart=/usr/lib/systemd/scripts/backup-var-log + diff --git a/system/backup-var-log.timer b/system/backup-var-log.timer new file mode 100644 index 0000000..489abe1 --- /dev/null +++ b/system/backup-var-log.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Backup /var/log every Tuesday at 05:30 + +[Timer] +# Every Tuesday at 5:30 +OnCalendar=Tue *-*-* 05:30 +Persistent=true + +[Install] +WantedBy=timers.target -- cgit v1.2.3-70-g09d2