#!/bin/bash

BACKUP_BASE=/opt

BACKUP_PATH="${BACKUP_BASE}/eDoc2"

if [ ! -d "${BACKUP_PATH}" ];then
    mkdir -p ${BACKUP_PATH}
fi

cat > /etc/rsyncd.conf << EOF
uid = root
gid = root
#port = 873
use chroot = yes
max connections = 100
timeout = 900
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
exclude = lost+found/
ignore errors
read only = false
list = false
auth users = edoc2_backup
secrets file = /etc/rsync.password

[edoc2]
path = ${BACKUP_PATH}
EOF

cat > /etc/rsync.password << EOF
edoc2_backup:1qaz2WSX
EOF

chmod 600 /etc/rsync.password

systemctl enable rsyncd
systemctl restart rsyncd
