From d9dc56d632c037702dcaead81a5bc5dac232ad94 Mon Sep 17 00:00:00 2001 From: Newnius Date: Fri, 27 Dec 2019 16:57:28 +0800 Subject: [PATCH] add rsync --- rsync/Dockerfile | 9 +++++++++ rsync/README.md | 35 +++++++++++++++++++++++++++++++++++ rsync/bootstrap.sh | 21 +++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 rsync/Dockerfile create mode 100644 rsync/README.md create mode 100755 rsync/bootstrap.sh diff --git a/rsync/Dockerfile b/rsync/Dockerfile new file mode 100644 index 0000000..8efbe08 --- /dev/null +++ b/rsync/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.10 + +MAINTAINER Newnius + +RUN apk add --no-cache rsync + +ADD bootstrap.sh /etc/bootstrap.sh + +ENTRYPOINT ["/etc/bootstrap.sh"] diff --git a/rsync/README.md b/rsync/README.md new file mode 100644 index 0000000..8fd52ef --- /dev/null +++ b/rsync/README.md @@ -0,0 +1,35 @@ +# Deploy rsync in docker + +## Deploy + +#### Run as Server + +```bash +docker run \ + --name rsync \ + -d \ + --restart always \ + --cpus 1.0 \ + --publish 873:873 \ + --mount type=bind,src=/etc/localtime,dst=/etc/localtime,readonly \ + --mount type=bind,src=/data/,dst=/data/ \ + --mount type=bind,src=/data/rsync/config/,dst=/config/ \ + newnius/rsync +``` + +#### Run as Client + +```bash +docker run \ + -it \ + --rm \ + --cpus 1.0 \ + --name rsync \ + --env AUTH_USER=newnius \ + --env AUTH_PASSWORD=password \ + --mount type=bind,src=/etc/localtime,dst=/etc/localtime,readonly \ + --mount type=bind,src=/data/,dst=/data/ \ + newnius/rsync rsync -avzP --delete --password-file=/etc/rsyncd.secret newnius@192.168.1.101::data/ /data/ +``` + + diff --git a/rsync/bootstrap.sh b/rsync/bootstrap.sh new file mode 100755 index 0000000..10711a1 --- /dev/null +++ b/rsync/bootstrap.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +if ! [[ -z "${AUTH_PASSWORD}" ]]; then + echo "$AUTH_PASSWORD" > /etc/rsyncd.secret + if ! [[ -z "${AUTH_USER}" ]]; then + echo "$AUTH_USER:$AUTH_PASSWORD" > /etc/rsyncd.secrets + chmod 600 /etc/rsyncd.secrets + fi +fi + +if [ -d /config/ ]; then + cp /config/rsync* /etc/ +fi + +if ! [[ -z $@ ]]; then + # use eval because commands likes `key=value command` would cause file not found error when using $@, but this eval will ruin current environment + eval $@ +else + rsync --daemon --config=/etc/rsyncd.conf + while pgrep rsync > /dev/null; do sleep 1; done +fi