-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_service.mo
executable file
·43 lines (35 loc) · 1.38 KB
/
backup_service.mo
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
#!/bin/bash
echo 'Waiting 10 seconds for things to start up and settle down...'
sleep 10
# Every day at a scheduled time do a backup
while true; do
echo "Backing up site data"
duply site_data backup
echo "Backing up configuration files"
# Get all developer keys
public_keys=(); gpg_recipients=""
for key in public_keys/*; do
test -f $key && \
public_keys+=( ${key##*/} ) && \
gpg_recipients=$gpg_recipients" -r ${key##*/}"
done
config_backup_dirname="{{PROJECT_BACKUP_CONFIG_BACKUP_DIRECTORY}}"
if [ "${#public_keys[@]}" -gt "0" ]; then
# Encrypt all config backups
gpg --yes --encrypt-files $gpg_recipients --trust-model always $config_backup_dirname/*.gz
# Send all encrypted config backups to target
if [[ ! -z "{{PROJECT_BACKUP_CONFIG_TARGET}}" ]]; then
scp $config_backup_dirname/*.gpg {{PROJECT_BACKUP_CONFIG_TARGET}}
else
echo "WARNING: Remote backup configuration TARGET is missing! Skipping remote backup of configuration files."
fi
else
echo "WARNING: No public keys available for encrypting configuration files. Skipping remote backup of configuration files."
fi
current_epoch=$(date +%s)
target_epoch=$(date -d '{{PROJECT_BACKUP_SCHEDULED_TIME}}' +%s)
sleep_seconds=$(( $target_epoch - $current_epoch ))
echo "Waiting '$sleep_seconds' seconds for next backup"
sleep "$sleep_seconds"
done
# vim: set ft=sh: