RSYNC SERVER

須安裝dialog

sudo apt install dialog

#!/bin/bash
#Author: kawsing
#Date: 2011/02/24
TMP="/tmp/IFselect.tmp$$"
bailout(){
rm -f "$TMP"
exit $1
}
DIALOG="dialog"
NETDEVICES="$(cat /proc/net/dev | awk -F: '/wl.|en./{print $1}')"
DEVICELIST=""
for DEVICE in $NETDEVICES; do DEVICELIST="$DEVICELIST ${DEVICE} Network_Card_${DEVICE##eth}"; done
$DIALOG --menu "選擇伺服器使用的網路介面" 0 0 0 $DEVICELIST 2>$TMP || bailout
read Card<$TMP; rm -f $TMP
echo $Card
$DIALOG --title "rsync_SERVER設定" --inputbox "請輸入授權的主機名稱 step1" 0 0 "myserverbackup" 2> "$TMP" || bailout
read resoult1 < "$TMP" ; rm -f "$TMP"
backhost="$resoult1"
$DIALOG --title "rsync_SERVER設定" --inputbox "請輸入儲存檔案的路徑 step2" 0 0 "/opt/mybackup" 2> "$TMP" || bailout
read resoult2 < "$TMP" ; rm -f "$TMP"
backpath="$resoult2"
if [ ! -d "$backpath" ]; then
mkdir -p "$backpath"
fi
$DIALOG --title "rsync_SERVER設定" --inputbox "請輸入授權的使用者名稱 step3" 0 0 "ubuntu" 2> "$TMP" || bailout
read resoult3 < "$TMP" ; rm -f "$TMP"
authuser="$resoult3"
$DIALOG --title "rsync_SERVER設定" --inputbox "請輸入授權者的密碼 step" 0 0 "secret" 2> "$TMP" || bailout
read resoult4 < "$TMP" ; rm -f "$TMP"
authpass="$resoult4"
if $DIALOG --title 設定rsyncd --yesno "\
以下將設定rsync伺服器
你確定要設定並執行嗎?" 0 0
then
mv /etc/default/rsync /etc/default/rsyncbak
echo "RSYNC_ENABLE=true" > /etc/default/rsync
cat > /etc/rsyncd.conf << END
[${backhost}]
path = $backpath
auth users = $authuser
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
read only = no
END
cat > /etc/rsyncd.secrets << END2
${authuser}:${authpass}
END2
sudo chown root.root /etc/rsyncd.secrets
sudo chmod 400 /etc/rsyncd.secrets
sudo /etc/init.d/rsync restart
echo "用戶端請建立包含授權密碼的密碼檔,如/root/rsyncd.secrets"
echo "sudo chmod 400 /root/rsyncd.secrets"
echo "執行指令:"
echo "rsync -rvlHpogDtS --password-file=/root/rsyncd.secrets 要備份的目錄 --exclude 不要備份的地方 ${authuser}@ip::${backhost}"
fi

Last updated