I could upload the files on QNAP NAS to Dropbox by shell script. It is useful to make replica of local backup file in NAS.
○ Environment:
NAS: QNAP TS-531P○Install Ubuntu LXC on NAS.
The shell script is executed on Ubuntu LXC. Before creating the shell scrip, Ubuntu LXC should be installed on NAS.
1. After setting up "Container Station" on NAS, open it.Select Create Container menu.
2. Click Create button for "Ubuntu LXC".
3. Set Shared Folder in Advanced Setting.
○Get Access Token of Dropbox.
The Access Token is needed to upload file by shell script. Access Token can be got as the followings.
1. Access to https://www.dropbox.com/developers/apps.
2. Click Create app button.
3. Choose an API -> Select "Dropbox API"
Choose the type of access you need -> Select "Full Dropbox"
Name your app -> input your App name (ex. QNAP_Uploader)
4. Click Create app button.
5. Open App you created, and click Generate button to create a new access token.
Copy the new access token, which is needed to set up Dropbox-Uploader.
○Install Dropbox-Uploader into Ubuntu LXC on NAS.
Dropbox-Uploader is the free shell application to operate Dropbox from shell command line including uploading files. It can work on any Distribution of Linux installed bash and curl.
Download and execute Dropbox-Uploader.
[root@servername~]# git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
[root@servername~]# cd Dropbox-Uploader/
[root@servername~]# ./dropbox_uploader.sh
In the first time you execute Dropbox-Uploader, Dropbox-Uploader asks Dropbox access token. Input the access token you created. Next time you execute Dropbox-Uploader, you can operate any command (upload, delete and so on) of it.
○Preparing the shell file to upload files into Dropbox.
This shell script works as the followings.
1. The func_upload_files function searches directories and files under {the local root path}/{first arg} recursively.
2. If a files is found, then the files are upload the files into {Dropbox root path}.
uploadDropbox.sh
#!/bin/sh
DROPBOX_ROOT="Write Dropbox root path to upload files."
ROOT="Write local root path to search the files to upload."
func_upload_files()
{
BASE_DIR=$ROOT$1/
DEST_DIR=$DROPBOX_ROOT/$1
SRC_DIR=`find $BASE_DIR -maxdepth 1 -type d | sort -nr | head -n 1`"/"
if [ $SRC_DIR != $BASE_DIR ]; then
/usr/local/Dropbox-Uploader/dropbox_uploader.sh delete $DROPBOX_ROOT$1
func_search_file $SRC_DIR $DEST_DIR
fi
}
func_search_file()
{
for d in `find $1 -maxdepth 1 -type d | sort -nr`; do
if [ $d != $1 ]; then
func_search_file $d $2
fi
done
for f in `find $1 -maxdepth 1 -type f | sort -nr`; do
FILENAME=${f##*$SRC_DIR}
#echo $DROPBOX_ROOT/$FILENAME
/usr/local/Dropbox-Uploader/dropbox_uploader.sh upload $f $2/$FILENAME
done
}
func_upload_files XXXX
func_upload_files YYYY
func_upload_files ZZZZ
...
...
...