-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a subscription is activated, send immediately a backup if available and start the timer for the nightly upload.
- Loading branch information
1 parent
ee3a18d
commit 166b6c0
Showing
4 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Unit] | ||
Description=Subscription cluster cloud backup | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=runagent cluster-backup | ||
ExecStart=runagent send-cluster-backup | ||
SyslogIdentifier=%N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Trigger sending cluster backup for subscription | ||
|
||
[Timer] | ||
OnBootSec=600 | ||
OnCalendar=3:00:00 | ||
Persistent=true | ||
RandomizedDelaySec=21600 | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
core/imageroot/var/lib/nethserver/cluster/bin/send-cluster-backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
set -e | ||
|
||
# Parse subscription configuration from Redis | ||
while IFS='=' read -r key value; do | ||
declare "${key}"="${value}" | ||
done < <(redis-hgetall cluster/subscription) | ||
|
||
function exit_error () | ||
{ | ||
echo "[ERROR]" "${@}" 1>&2 | ||
exit 1 | ||
} | ||
|
||
function send_cluster_backup_nsent () | ||
{ | ||
curl -X POST \ | ||
--silent \ | ||
--user-agent NethBackup \ | ||
--location-trusted \ | ||
--user "${system_id:?}:${auth_token:?}" \ | ||
--header 'NethBackup-Action: backup-send' \ | ||
--header "NethBackup-Parameters: LK=${system_id:?}&fname=dump.json.gz.gpg" \ | ||
--data-binary "@${encrypted_file}" \ | ||
https://backupd.nethesis.it/backup >/dev/null | ||
} | ||
|
||
sendfunc="send_cluster_backup_${provider:?missing subscription config}" | ||
if [[ $(type -t "${sendfunc}") != function ]]; then | ||
echo "[WARNING] Invalid provider, ignored: ${provider}" 1>&2 | ||
exit 0 | ||
fi | ||
|
||
if [[ -f backup/dump.md5 ]]; then | ||
prev_backup_hash="$(< backup/dump.md5)" | ||
else | ||
prev_backup_hash="never_uploaded" | ||
fi | ||
|
||
backup_file=backup/dump.json.gz | ||
encrypted_file=backup/dump.json.gz.gpg | ||
backup_hash=$(md5sum "${backup_file}" | awk '{ print $1 }') | ||
|
||
if [[ "${prev_backup_hash}" == "${backup_hash}" ]]; then | ||
echo "Backup file already uploaded, nothing to do" 1>&2 | ||
elif [[ -f "${encrypted_file}" ]]; then | ||
${sendfunc} | ||
# Backup upload successful, update the reference file | ||
echo "${backup_hash}" > backup/dump.md5 | ||
echo "Backup uploaded to provider ${provider} with hash ${backup_hash}" 1>&2 | ||
else | ||
echo "[ERROR] Could not find ${encrypted_file} for upload" 1>&2 | ||
exit 1 | ||
fi |