Files
hassio-addons/duplicacy/run.sh
2021-07-20 10:49:44 -04:00

42 lines
2.2 KiB
Bash

#!/usr/bin/env bashio
# grab user variables
bashio::log.info "Setting the variables from the config..."
BACKUP_ID=$(bashio::config 'backupID')
PROTOCOL=$(bashio::config 'protocol')
PROTOCOL="sftp"
SSH_USERNAME=$(bashio::config 'ssh_username')
SSH_PASSWORD=$(bashio::config 'ssh_password')
BACKUP_SERVER=$(bashio::config 'server')
SSH_PORT=$(bashio::config 'ssh_port')
BACKUP_SERVER_PATH=$(bashio::config 'path')
FILTERS=$(bashio::config 'filters')
DAYS_TO_KEEP=$(bashio::config 'days_to_keep')
bashio::log.debug "BACKUP_ID set to ${BACKUP_ID}. Should be set to $(bashio::config 'backupID')"
bashio::log.debug "PROTOCOL set to ${PROTOCOL}. Should be set to $(bashio::config 'protocol')"
bashio::log.debug "SSH_USERNAME set to ${SSH_USERNAME}. Should be set to $(bashio::config 'ssh_username')"
bashio::log.debug "SSH_PASSWORD set to ${SSH_PASSWORD}. Should be set to $(bashio::config 'ssh_password')"
bashio::log.debug "BACKUP_SERVER set to ${BACKUP_SERVER}. Should be set to $(bashio::config 'server')"
bashio::log.debug "SSH_PORT set to ${SSH_PORT}. Should be set to $(bashio::config 'ssh_port')"
bashio::log.debug "BACKUP_SERVER_PATH set to ${BACKUP_SERVER_PATH}. Should be set to $(bashio::config 'path')"
bashio::log.debug "FILTERS set to ${FILTERS}. Should be set to $(bashio::config 'filters')"
bashio::log.debug "DAYS_TO_KEEP set to ${DAYS_TO_KEEP}. Should be set to $(bashio::config 'days_to_keep')"
# edit the /.duplicacy/preferences file
bashio::log.info "Creating /.duplicacy preferences file..."
sed --in-place 's/<BACKUP_ID>/'${BACKUP_ID}'/' /.duplicacy/preferences
sed --in-place 's/<PROTOCOL>/'${PROTOCOL}'/' /.duplicacy/preferences
sed --in-place 's/<SSH_USERNAME>/'${SSH_USERNAME}'/' /.duplicacy/preferences
sed --in-place 's/<SSH_PASSWORD>/'${SSH_PASSWORD}'/' /.duplicacy/preferences
sed --in-place 's/<BACKUP_SERVER>/'${BACKUP_SERVER}'/' /.duplicacy/preferences
sed --in-place 's/<SSH_PORT>/'${SSH_PORT}'/' /.duplicacy/preferences
sed --in-place 's~<BACKUP_SERVER_PATH>~'${BACKUP_SERVER_PATH}'~' /.duplicacy/preferences
# create the filters file
echo ${FILTERS} | jq -r '.[]' >> /.duplicacy/filters
# run the backup
/duplicacy -verbose -log backup -stats
# run the clean up
find /backup/* -type f -name '*.tar' -mtime +${DAYS_TO_KEEP} -exec rm -vf {} \;