From fd3b4a68b7ba29e77a3147f8e5fced19eeb294d4 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 20 Mar 2015 01:32:42 +0100 Subject: backup-websites: Adding first version of backup-websites script, service and timer. --- scripts/backup-websites | 32 ++++++++++++++++++++++++++++++++ system/backup-websites.service | 11 +++++++++++ system/backup-websites.timer | 10 ++++++++++ 3 files changed, 53 insertions(+) create mode 100755 scripts/backup-websites create mode 100644 system/backup-websites.service create mode 100644 system/backup-websites.timer diff --git a/scripts/backup-websites b/scripts/backup-websites new file mode 100755 index 0000000..285f525 --- /dev/null +++ b/scripts/backup-websites @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Backup websites + +timestamp="$(date +"%Y%m%d-%H%M%S")-" + +# If the backup location doesn't exist yet, create it +if [ ! -d $website_folder_destination ]; then + mkdir -p $website_folder_destination +fi + +# If the parent directory of the backup source exists, enter it +if [ -d $website_folder_source ]; then + cd $website_folder_source +else + exit 1 +fi + +for subfolder in $website_folder_source* +do + subfolder=$(basename $subfolder) + echo "$subfolder --> $website_folder_destination$timestamp$subfolder$tar_suffix$gpg_suffix" + # tar to /tmp + tar cfJ "$tmp$timestamp$subfolder$tar_suffix" $subfolder + # gpg to backup location + gpg -e \ + -r "$gpg_public_key" \ + -o "$website_folder_destination$timestamp$subfolder$tar_suffix$gpg_suffix" \ + $tmp$timestamp$subfolder$tar_suffix + # remove tar in /tmp + rm -f $tmp$timestamp$subfolder$tar_suffix +done + diff --git a/system/backup-websites.service b/system/backup-websites.service new file mode 100644 index 0000000..c350b21 --- /dev/null +++ b/system/backup-websites.service @@ -0,0 +1,11 @@ +[Unit] +Description=Backup Websites +ConditionFileIsExecutable=/usr/lib/systemd/scripts/backup-websites + +[Service] +EnvironmentFile=/etc/backup-settings +Nice=19 +IOSchedulingClass=2 +IOSchedulingPriority=7 +ExecStart=/usr/lib/systemd/scripts/backup-websites + diff --git a/system/backup-websites.timer b/system/backup-websites.timer new file mode 100644 index 0000000..5c08795 --- /dev/null +++ b/system/backup-websites.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Backup websites every 1st and 16th of each montih at 03:00 + +[Timer] +# Every 1st and 16th of each month at 03:00 +OnCalendar=*-*-1,16 03:00 +Persistent=true + +[Install] +WantedBy=timers.target -- cgit v1.2.3-54-g00ecf