Skip to content

Commit fda3db0

Browse files
authored
Merge pull request #17 from jokay/feature/exclude-folders
Support excluding directories
2 parents c12c40c + 8b5e8f2 commit fda3db0

4 files changed

Lines changed: 68 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.3.0](https://github.com/jokay/docker-loxone-backup/releases/tag/1.3.0) (2022-12-19)
4+
5+
### Features
6+
7+
- Excluding specific directories from backup. ([#11])
8+
39
## [1.2.0](https://github.com/jokay/docker-loxone-backup/releases/tag/1.2.0) (2022-12-08)
410

511
### Features
@@ -21,5 +27,6 @@
2127
Initial release.
2228

2329
[#9]: https://github.com/jokay/docker-loxone-backup/issues/9
30+
[#11]: https://github.com/jokay/docker-loxone-backup/issues/11
2431
[#12]: https://github.com/jokay/docker-loxone-backup/issues/12
2532
[#14]: https://github.com/jokay/docker-loxone-backup/issues/14

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ None
3838
For this Docker image, it's strongly advised to create a **separate user** who
3939
has only the permission **FTP**.
4040

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

5051
## Samples
5152

src/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ENV LOXONE_PASSWORD ""
1111
ENV INTERVAL 86400
1212
ENV KEEP_DAYS 30
1313
ENV VERBOSE false
14+
ENV EXCLUDE_DIRS ""
1415

1516
RUN apk add --update --no-cache \
1617
tzdata \

src/entrypoint.sh

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,73 @@ log_sub() {
88
printf " | %s\n" "${1}"
99
}
1010

11-
log "xjokay/loxone-backup ${VERSION}"
11+
config() {
12+
log "Configuration"
13+
log_sub ""
14+
log_sub "INTERVAL: ${INTERVAL}"
15+
log_sub "KEEP_DAYS: ${KEEP_DAYS}"
16+
log_sub "VERBOSE: ${VERBOSE}"
17+
log_sub "EXCLUDE_DIRS: ${EXCLUDE_DIRS}"
18+
}
1219

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

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

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

23-
if [ "${VERBOSE}" = "true" ]; then
24-
FTP_PARAMS="${FTP_PARAMS} -vvv"
25-
fi
35+
if [ "${VERBOSE}" = "true" ]; then
36+
FTP_PARAMS="${FTP_PARAMS} -vvv"
37+
fi
2638

27-
while :; do
28-
cd "/data" || exit
39+
if [ -n "${EXCLUDE_DIRS}" ]; then
40+
for EXCLUDE_DIR in $(printf "%s" "${EXCLUDE_DIRS}" | sed 's/,/ /g'); do
41+
rm -rf "/data/current/${EXCLUDE_DIR}"
42+
FTP_PARAMS="${FTP_PARAMS} -x '${EXCLUDE_DIR}/'"
43+
done
44+
fi
45+
}
2946

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

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

3757
log "Cleanup backups older than ${KEEP_DAYS} day(s) ..."
3858
find . -mtime "+${KEEP_DAYS}" -print0 | xargs --no-run-if-empty rm
3959
fi
60+
}
61+
62+
log "xjokay/loxone-backup ${VERSION}"
63+
64+
check
65+
66+
config
67+
68+
setup
69+
70+
ftp_params
71+
72+
while :; do
73+
cd "/data" || exit
74+
75+
backup
76+
77+
cleanup
4078

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

0 commit comments

Comments
 (0)