Files
hassio-addons/PBS-Client/run.sh

71 lines
2.6 KiB
Bash

#!/usr/bin/env bashio
# grab user variables
bashio::log.info "Setting the variables from the config..."
AUTH=$(bashio::config 'auth')
USERNAME=$(bashio::config 'username')
PASSWORD=$(bashio::config 'password')
PBS_HOST=$(bashio::config 'pbs_host')
PBS_PORT=$(bashio::config 'pbs_port')
PBS_FINGERPRINT=$(bashio::config 'pbs_fingerprint')
DATASTORE=$(bashio::config 'datastore')
NAMESPACE=$(bashio::config 'namespace')
INCLUDE=$(bashio::config 'include')
DAYS_TO_KEEP=$(bashio::config 'days_to_keep')
bashio::log.info "PBS_HOST set to ${PBS_HOST}"
bashio::log.info "PBS_PORT set to ${PBS_PORT}"
bashio::log.info "PBS_FINGERPRINT set to ${PBS_FINGERPRINT}"
bashio::log.info "DATASTORE set to ${DATASTORE}"
bashio::log.info "NAMESPACE set to ${NAMESPACE}"
bashio::log.info "USERNAME set to ${USERNAME}"
bashio::log.info "AUTH set to ${AUTH}"
bashio::log.info "INCLUDE set to ${INCLUDE}"
bashio::log.info "DAYS_TO_KEEP set to ${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
# have to use ~ since the path contains slashes
#sed --in-place 's~<BACKUP_SERVER_PATH>~'${BACKUP_SERVER_PATH}'~' /.duplicacy/preferences
# create the filters file
#bashio::log.info "Creating /.duplicacy/filters file..."
#for filter in ${FILTERS}; do
# echo ${filter} >> /.duplicacy/filters
#done
# set environment variables
bashio::log.info "Setting environment variables"
export PBS_PASSWORD="${PASSWORD}"
export PBS_REPOSITORY="${USERNAME}@${AUTH}@${PBS_HOST}:${PBS_PORT}:${DATASTORE}"
export PBS_FINGERPRINT="${PBS_FINGERPRINT}"
bashio::log.info "PBS_REPOSITORY set to ${PBS_REPOSITORY}"
INCLUDE_DEV=""
for I in ${INCLUDE}; do
INCLUDE_DEV+="${I}.pxar:/${I}"
done
bashio::log.info "INCLUDE_DEV set to ${INCLUDE_DEV}"
/usr/bin/proxmox-backup-client version
exit 0
# run the backup
bashio::log.info "Running the PBS backup..."
if [ -z "${NAMESPACE}" ]; then
/usr/bin/proxmox-backup-client backup ${INCLUDE_DEV}
else
/usr/bin/proxmox-backup-client backup --ns ${NAMESPACE} ${INCLUDE_DEV}
fi
# run the clean up
bashio::log.info "Cleaing up backups older than ${DAYS_TO_KEEP} day(s)..."
find /backup/* -type f -name '*.tar' -mtime +${DAYS_TO_KEEP} -exec rm -vf {} \;