■ 준비물
- Storage를 탑재한 Linux 머신에 rclone 설치
- 클라이언트 윈도우 PC에 rclone 설치

■ rclone 설치

curl -O https://downloads.rclone.org/rclone-current-linux-arm.zip
unzip rclone-current-linux-arm.zip
cp -fv rclone-*-linux-arm/rclone /usr/bin/
rm -rf rclone-*

윈도우는 https://rclone.org/downloads/ 에서 다운로드 받아 설치한다.

■ 리눅스 서버에서 rclone 설정

아래와 같은 과정으로 설정한다.

$ rclone config
2019/12/02 11:28:30 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> onedrive
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
19 / Microsoft OneDrive
   \ "onedrive"
Storage> 19
** See help for onedrive backend at: https://rclone.org/onedrive/ **

Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> [그냥 엔터]
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> [그냥 엔터]

Edit advanced config? (y/n)
y) Yes
n) No
y/n> n
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
        rclone authorize "onedrive"
Then paste the result below:

■ 윈도우PC에서 rclone 리모트 인증

윈도우 커맨드 프롬트프에서 rclone & 웹브라우저를 사용해서 아래와 같이 인증 받는다.
rclone authorize "onedrive"




■ 리눅스 서버에서 rclone 인증키 입력

result> 여기에 윈도우PC에서 받은 키를 붙여 넣는다. {"access_token":"eyJ0edsfsaer4gfw34...wem4j0SZNqI3SAA","expiry":"2019-12-02T12:30:46.2077483+09:00"}
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Type in driveID
   \ "driveid"
 4 / Type in SiteID
   \ "siteid"
 5 / Search a Sharepoint site
   \ "search"
Your choice> 1
Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=b!kowefawefawefawefawefasdfq23fq23fq23fq23g54gw534rff4f4rgfrg3_HKH
Chose drive to use:> 0
Found drive 'root' of type 'business', URL: https://wenzhan1o-my.sharepoint.com/personal/myid_hotmail_com/Documents
Is that okay?
y) Yes
n) No
y/n> y
type = onedrive
token = {"access_token":"eyJ0eXAieiwoef...pbHyowem4j0SZNqI3SAA","expiry":"2019-12-02T12:30:46.2077483+09:00"}
drive_id = b!kodQ3NkYXUCYrawefawefawefawefawefw4fu89w4hfwifh0ssQHRqznObX2_HKH
drive_type = business
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:

Name                 Type
====                 ====
onedrive             onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

■ rclone-sync.sh를 사용한 동기화

아래의 스크립트를 사용하여 동기화 한다.
이 스크립트는 중복 실행 방지 기능이 있으므로 cron 데몬에 10분 간격으로 실행되도록 해 놓으면 자동으로 동기화 할 수 있다.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"  # get cur dir of this script
progName=$(basename -- "$0")
cd $DIR
echo "$progName $ver  written by Claude Pageau"
: '
 If lockCheckFile=True then script checks pi-timolo.sync file exists
 Otherwise no sync is attempted.  This can be useful for
 Low Bandwidth connections with low frequency of motion tracking events

#  Customize rclone sync variables Below
# ---------------------------------------

lockFileCheck=false       # true= Checks for pi-timolo.sync file. false = No Check (case sensitive)
rcloneName="onedrive"     # "rclone listremotes" 커맨드로 보이는 클라우드 스토리지 명
syncRoot="/usr"           # 로컬 루트 폴더 (chroot되는 폴더)
localDir="share/X11"            # 로컬 루트 폴더를 기준으로 한 로컬 폴더명
remoteDir="/X11/123/456"          # 원격지 폴더 (폴더가 없으면 생성된다)
rcloneParam="copy"        # 동기화 방법
                          # sync: 양방향 동기화
                          # copy: 로컬 스토리지→원격 스토리지로 복사
                          # move: 로컬 스토리지→원격 스토리지로 이동
# ---------------------------------------

# Display Users Settings
echo "----------- SETTINGS -------------

lockFileCheck : $lockFileCheck
rcloneName    : $rcloneName
syncRoot      : $syncRoot
localDir      : $localDir
remoteDir     : $remoteDir
rcloneParam   : $rcloneParam   (Options are sync, copy or move)



cd $syncRoot   # Change to local rclone root folder
if pidof -o %PPID -x "$progName"; then
    echo "WARN  - $progName Already Running. Only One Allowed."
    if [ -f /usr/bin/rclone ]; then    #  Check if rclone installed
        rclone version   # Display rclone version
        if [ ! -d "$localDir" ] ; then   # Check if Local sync Folder Exists
           echo "---------------------------------------------------"
           echo "ERROR : localDir=$localDir Does Not Exist."
           echo "        Please Investigate Bye ..."
           exit 1
        /usr/bin/rclone listremotes | grep "$rcloneName"  # Check if remote storage name exists
        if [ $? == 0 ]; then    # Check if listremotes found anything
            if $lockFileCheck ; then
                if [ -f "$lockFilePath" ] ; then  # Check if sync lock file exists
                    echo "INFO  : Found Lock File $lockFilePath"
                    echo "        rclone $rcloneParam is Required."
                    echo "INFO  : Lock File Not Found: $lockFilePath"
                    echo "        rclone $rcloneParam is Not Required."
                    echo "Exiting $progName ver $ver"
                    exit 0
            echo "INFO  : /usr/bin/rclone $rcloneParam -v $localDir $rcloneName:$remoteDir"
            echo "        One Moment Please ..."
            /usr/bin/rclone $rcloneParam -v $localDir $rcloneName:$remoteDir
            if [ ! $? -eq 0 ]; then
                echo "---------------------------------------------------"
                echo "ERROR : rclone $rcloneParam Failed."
                echo "        Review rclone %rcloneParam Output for Possible Cause."
                echo "INFO  : rclone $rcloneParam Successful ..."
                if $lockFileCheck ; then
                    if [ -f "$lockFilePath" ] ; then
                        echo "INFO  : Delete File $lockFilePath"
                        rm -f $lockFilePath
            echo "---------------------------------------------------"
            echo "ERROR : rcloneName=$rcloneName Does not Exist"
            echo "INFO  : List Remote Storage Names that are Setup."
            echo "rclone listremotes"
            echo "-------------------"
            rclone listremotes
            echo "--------------------"
            echo "INFO  : If listremotes Listing is Empty, Read pi-timolo Wiki"
            echo "        How to Setup a Remote Storage Name."
        echo "ERROR : /usr/bin/rclone Not Installed."
        echo "        You Must Install and Configure rclone"
        echo "        See pi-timolo Wiki for Details"
echo "---------------------------------------------------"
echo "Exiting $progName ver $ver Bye ..."