Initial addition of timegaps pruning

Might want to move from two cron tasks to a single one where rclone and prune are executed sequentially
This commit is contained in:
ViViDboarder 2021-11-29 10:39:52 -08:00
parent 9891b6d111
commit f678ec65b9
5 changed files with 47 additions and 6 deletions

View File

@ -27,6 +27,18 @@ The rclone destination in the form `<drive>:<path>`. See note above on how to se
Rclone command to execute (`sync`, `copy`, or `move`)
### Option: `prune.rules`
Rules for pruning backups based on time gap configuration. This is done with a tool caled [timegaps](https://gehrcke.de/timegaps/) and is optional.
### Option: `prune.cron`
Cron schedule to run the prune job. Need help? https://crontab.guru/
### Option: `prune.delete`
Rather than logging, if set to true, this will delete backups based on the rules set in `prune.rules`.
### Option: `credentials.username`
Username to view web UI

View File

@ -6,9 +6,14 @@ ENV LANG C.UTF-8
ARG BUILD_ARCH=aarch64
ARG VERSION=v1.55.1
# Install rclone
COPY install_rclone.sh /
RUN /install_rclone.sh "${VERSION}" "${BUILD_ARCH}"
# Add timegaps for pruning backups
RUN apk add python3=3.9.5-r2 py3-pip=20.3.4-r1
RUN pip install timegaps==0.1.1
ENV XDG_CONFIG_HOME=/data
COPY rootfs /

View File

@ -23,6 +23,10 @@ options:
cron: "0 * * * *"
destination: "<drive>:<path>"
sync_command: sync
prune:
rules: ""
cron: ""
delete: false
credentials:
username: homeassistant
password: homeassistant
@ -34,6 +38,10 @@ schema:
cron: str
destination: str
sync_command: list(sync|copy|move)
prune:
rules: str
cron: str
delete: bool
credentials:
username: str
password: str

View File

@ -8,13 +8,13 @@ bashio::config.require.password 'credentials.password'
bashio::config.suggest.true 'tls.ssl'
bashio::config.require.ssl 'tls' 'tls.certfile' 'tls.keyfile'
sync_command=$(bashio::config 'sync_command')
destination=$(bashio::config 'destination')
SYNC_COMMAND=$(bashio::config 'sync_command')
DESTINATION=$(bashio::config 'destination')
username=$(bashio::config 'credentials.username')
password=$(bashio::config 'credentials.password')
USERNAME=$(bashio::config 'credentials.username')
PASSWORD=$(bashio::config 'credentials.password')
command="rclone rc --user \"$username\" --pass \"$password\" sync/$sync_command srcFs=/backup dstFs=$destination _async=true"
command="rclone rc --user \"$USERNAME\" --pass \"$PASSWORD\" sync/$SYNC_COMMAND srcFs=/backup dstFs=$DESTINATION _async=true"
echo "$(bashio::config 'cron') $command" > /etc/crontabs/root
echo "$(bashio::config 'cron') $command" >> /etc/crontabs/root
crontab -l

View File

@ -0,0 +1,16 @@
#! /usr/bin/with-contenv bashio
bashio::log.info "Configuring pruning with timegaps..."
TIMEGAPS_RULES=$(bashio::config 'prune.rules')
TIMEGAPS_CRON=$(bashio::config 'prune.cron')
TIMEGAPS_DELETE=""
if bashio::config.true 'prune.delete'; then
TIMEGAPS_DELETE="--delete"
fi
if [ -z "$TIMEGAPS_RULES" ] && [ -z "$TIMEGAPS_CRON" ]; then
COMMAND="timegaps $TIMEGAPS_DELETE $TIMEGAPS_RULES /backups/*.tar"
echo "$TIMEGAPS_CRON $COMMAND" >> /etc/crontabs/root
crontab -l
fi