Skip to content

Commit

Permalink
Merge pull request #17 from jokay/feature/exclude-folders
Browse files Browse the repository at this point in the history
Support excluding directories
  • Loading branch information
jokay authored Dec 19, 2022
2 parents c12c40c + 8b5e8f2 commit fda3db0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.3.0](https://github.com/jokay/docker-loxone-backup/releases/tag/1.3.0) (2022-12-19)

### Features

- Excluding specific directories from backup. ([#11])

## [1.2.0](https://github.com/jokay/docker-loxone-backup/releases/tag/1.2.0) (2022-12-08)

### Features
Expand All @@ -21,5 +27,6 @@
Initial release.

[#9]: https://github.com/jokay/docker-loxone-backup/issues/9
[#11]: https://github.com/jokay/docker-loxone-backup/issues/11
[#12]: https://github.com/jokay/docker-loxone-backup/issues/12
[#14]: https://github.com/jokay/docker-loxone-backup/issues/14
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ None
For this Docker image, it's strongly advised to create a **separate user** who
has only the permission **FTP**.

| ENV field | Req. / Opt. | Description |
|-----------------|--------------|----------------------------------------------------------------------------------------|
| LOXONE_IP | **Required** | IP or url of the Loxone Miniserver. |
| LOXONE_USERNAME | **Required** | Loxone username. |
| LOXONE_PASSWORD | **Required** | Loxone password. |
| INTERVAL | *Optional* | Interval of backups, default is `86400` seconds (24h). |
| KEEP_DAYS | *Optional* | Cleanup of backups older than x days. Default is `30`. Can be disabled by setting `0`. |
| VERBOSE | *Optional* | If `true`, increases the verbosity level. Default ist `false`. |
| ENV field | Req. / Opt. | Description |
|-----------------|--------------|---------------------------------------------------------------------------------------------|
| LOXONE_IP | **Required** | IP or url of the Loxone Miniserver. |
| LOXONE_USERNAME | **Required** | Loxone username. |
| LOXONE_PASSWORD | **Required** | Loxone password. |
| INTERVAL | *Optional* | Interval of backups. Default is `86400` seconds (24h). |
| KEEP_DAYS | *Optional* | Cleanup of backups older than x days. Default is `30`. Can be disabled by setting `0`. |
| VERBOSE | *Optional* | If `true`, increases the verbosity level. Default is `false`. |
| EXCLUDE_DIRS | *Optional* | Comma separated list of folders to exclude, e.g. `dir1,dir2`. Default is excluding nothing. |

## Samples

Expand Down
1 change: 1 addition & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ENV LOXONE_PASSWORD ""
ENV INTERVAL 86400
ENV KEEP_DAYS 30
ENV VERBOSE false
ENV EXCLUDE_DIRS ""

RUN apk add --update --no-cache \
tzdata \
Expand Down
64 changes: 51 additions & 13 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,73 @@ log_sub() {
printf " | %s\n" "${1}"
}

log "xjokay/loxone-backup ${VERSION}"
config() {
log "Configuration"
log_sub ""
log_sub "INTERVAL: ${INTERVAL}"
log_sub "KEEP_DAYS: ${KEEP_DAYS}"
log_sub "VERBOSE: ${VERBOSE}"
log_sub "EXCLUDE_DIRS: ${EXCLUDE_DIRS}"
}

mkdir -p "/data/current" "/data/archives"
check() {
if [ -z "${LOXONE_IP}" ] || [ -z "${LOXONE_USERNAME}" ] || [ -z "${LOXONE_PASSWORD}" ]; then
log "Required environment variables are missing!"
log_sub "Please specify LOXONE_IP, LOXONE_USERNAME and LOXONE_PASSWORD."
exit 1
fi
}

if [ -z "${LOXONE_IP}" ] || [ -z "${LOXONE_USERNAME}" ] || [ -z "${LOXONE_PASSWORD}" ]; then
log "Required environment variables are missing!"
log_sub "Please specify LOXONE_IP, LOXONE_USERNAME and LOXONE_PASSWORD."
exit 1
fi
setup() {
mkdir -p "/data/current" "/data/archives"
}

FTP_PARAMS="-a -n -e -P=5 --use-pget-n=1 --skip-noaccess --use-cache --log=ftp.log"
ftp_params() {
FTP_PARAMS="-a -n -e -P=5 --use-pget-n=1 --skip-noaccess --use-cache --log=ftp.log"

if [ "${VERBOSE}" = "true" ]; then
FTP_PARAMS="${FTP_PARAMS} -vvv"
fi
if [ "${VERBOSE}" = "true" ]; then
FTP_PARAMS="${FTP_PARAMS} -vvv"
fi

while :; do
cd "/data" || exit
if [ -n "${EXCLUDE_DIRS}" ]; then
for EXCLUDE_DIR in $(printf "%s" "${EXCLUDE_DIRS}" | sed 's/,/ /g'); do
rm -rf "/data/current/${EXCLUDE_DIR}"
FTP_PARAMS="${FTP_PARAMS} -x '${EXCLUDE_DIR}/'"
done
fi
}

backup() {
log "Backup files from Loxone (${LOXONE_IP}) ..."
lftp "${LOXONE_IP}" -u "${LOXONE_USERNAME},${LOXONE_PASSWORD}" -e "set ssl:verify-certificate false; mirror ${FTP_PARAMS} . current; quit"
tar -czf "archives/loxone_backup_${LOXONE_IP}_$(date +%Y-%m-%d_%H-%M-%S).tar.gz" "current/"
}

cleanup() {
if [ "${KEEP_DAYS}" -gt 0 ]; then
cd "/data/archives" || exit

log "Cleanup backups older than ${KEEP_DAYS} day(s) ..."
find . -mtime "+${KEEP_DAYS}" -print0 | xargs --no-run-if-empty rm
fi
}

log "xjokay/loxone-backup ${VERSION}"

check

config

setup

ftp_params

while :; do
cd "/data" || exit

backup

cleanup

next=$(date -d "@$(($(date +%s) + INTERVAL))" +%Y-%m-%dT%H:%M:%S%z)
log "Next run on ${next} ..."
Expand Down

0 comments on commit fda3db0

Please sign in to comment.