Open brmo opened 9 months ago
@brmo Sorry for the delay, I was on vacation.
Here is an example file in Ansible land:
#!/usr/bin/env bash
# Prevent multiple simultaneous executions
[ "${FLOCKER}" != "`realpath '$0'`" ] && exec env FLOCKER="`realpath '$0'`" flock -en "$0" "$0" "$@" || :
{% for destination in (kopia_backup_filesystem_destinations + kopia_backup_s3_destinations) %}
if {{ destination.precondition }}; then
echo "----------------------------------------------------------------"
echo "Backup(s) started for {{destination.type}}:{{destination.name}}."
echo "----------------------------------------------------------------"
# Get the PING URL for the check
CHECK=$(curl -Ss --header "X-Api-Key: {{ healthcheck.apiTokens.backup }}" https://healthchecks.example.com/api/v1/checks/?tag={{destination.name}}&tag={{destination.type}}&tag={{inventory_hostname}})
# There may be more than one check in the result for each source that needs to go to the destination.
URLS=$(echo $CHECK | jq -rc '.checks[].ping_url')
# Indicate that begin snapshot(s)
while IFS= read -r URL; do
curl -Ss $URL/start > /dev/null
done <<< "$URLS"
# Perform snapshot operation
/usr/bin/kopia snapshot create --parallel {{kopia_backup_parallel}} --all --config-file="{{destination.config}}" --password="{{destination.passcode}}"
# Indicate that snapshot(s) completion
if [ $? -eq 0 ]; then
echo "Backup(s) succeeded for {{destination.type}}:{{destination.name}}."
while IFS= read -r URL; do
curl -Ss $URL > /dev/null
done <<< "$URLS"
else
echo "Backup(s) failed for {{destination.type}}:{{destination.name}}."
while IFS= read -r URL; do
curl -Ss $URL/fail > /dev/null
done <<< "$URLS"
fi
fi
{% endfor %}
And the resulting file will be similar as this depending on your backup destinations:
#!/usr/bin/env bash
# Prevent multiple simultaneous executions
[ "${FLOCKER}" != "`realpath '$0'`" ] && exec env FLOCKER="`realpath '$0'`" flock -en "$0" "$0" "$@" || :
if mountpoint -q /mnt/seagate/; then
echo "----------------------------------------------------------------"
echo "Backup(s) started for filesystem:seagate."
echo "----------------------------------------------------------------"
# Get the PING URL for the check
CHECK=$(curl -Ss --header "X-Api-Key: ****" https://healthchecks.example.com/api/v1/checks/?tag=seagate&tag=filesystem&tag=t440s)
# There may be more than one check in the result for each source that needs to go to the destination.
URLS=$(echo $CHECK | jq -rc '.checks[].ping_url')
# Indicate that begin snapshot(s)
while IFS= read -r URL; do
curl -Ss $URL/start > /dev/null
done <<< "$URLS"
# Perform snapshot operation
/usr/bin/kopia snapshot create --parallel 4 --all --config-file="/home/kopia/.config/kopia/repository.seagate.filesystem.config" --password="*****"
# Indicate that snapshot(s) completion
if [ $? -eq 0 ]; then
echo "Backup(s) succeeded for filesystem:seagate."
while IFS= read -r URL; do
curl -Ss $URL > /dev/null
done <<< "$URLS"
else
echo "Backup(s) failed for filesystem:seagate."
while IFS= read -r URL; do
curl -Ss $URL/fail > /dev/null
done <<< "$URLS"
fi
fi
Do you have a example file by chance?
kopia_service_script_file: /home/kopia/kopia.script
Thanks!