OneDrive如何实现跨平台数据同步?

OneDrive如何实现跨平台数据同步?目标背景下:通过将网盘放置在桌面上。以本地磁盘的方式挂载到每一台PC上,直接以类似本地磁盘操作的方式实现多平台多PC的数据共享与

同步如果您的需求亦此,上车吧。

一个驱动器

话说,OneDrive对网内用户并不友好,尤其是个人的网页版是无法在墙内访问的。

其次,个人版的OneDrive只有5G容量,白嫖的教育版5T起步,但教育邮箱是个门生物学,而且理论上管理员是可以查看您存储的内容甚至删除,所以果您的邮箱是临时申请的,请不要存储私有内容,顺便一提,个人版是有专门的保密柜的,每次打开强制身份认证,20分钟不使用自动关闭。

不过即使是临时邮箱,只要管理员没有恶意,不用担心你的邮箱被别人申请操纵你的网盘,它只在申请时会用到,office帐户的操作不再使用,因此管理员不存在恶意的情况下相对安全。

总结一下:

个人版:容量小,安全,墙内不支持网页版(所以某些认证会延长)

教育版:容量大,安全性相对低,支持网页版访问

你会做何选择呢?成年人表示全都有,2333333

视窗

Windows下的部署接近傻瓜式,得益于RaiDrive。

官网:https://www.raidrive.com/

这个安装和添加操作是在无脑,在此不做扩展,官网没找到免费下载的点,在此分享自用的1.6版本。

https://pan.baidu.com/s/1sWBzh3qraE8_wjUCeC3aXQ

借助RaiDrive我们可以将OneDrive以磁盘的方式挂载到本地,最终效果图:

的Linux

Linux平台首先说下我走过的坑。

开始为了偷懒选择的是onedrive-d,对个人版的认证需要访问网页,即onedrive.live.com,这就是我上面提到的认证替代,其次对教育版的认证是登录微软帐户,然而,难道微软账户和office不是一个东西?

笔者最终选择放弃,选择rclone,以下内容请以root运行,笔者已建好兔子面具,新建一个胡萝卜插图。

rclone安装

wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh

rclone configCurrent remotes:NameType========rabbitmask onedrivee)Edit existing remoten)New remoted)Delete remoter)Rename remotec)Copy remotes)Set configuration passwordq)Quit confige/n/d/r/c/s/q> nname> carrotType of storage to configure.Enter a string value.PressEnterfor the default(“”).Choose a number from below, or type in your own value 1/ 1Fichier \ “fichier” 2/Aliasfor an existing remote \ “alias” 3/AmazonDrive \ “amazon cloud drive” 4/AmazonS3CompliantStorageProvider(AWS,Alibaba,Ceph,DigitalOcean,Dreamhost,IBMCOS,Minio, etc) \ “s3” 5/BackblazeB2 \ “b2” 6/Box \ “box” 7/Cache a remote \ “cache” 8/CitrixSharefile \ “sharefile” 9/Dropbox \ “dropbox”10/Encrypt/Decrypt a remote \ “crypt”11/FTPConnection \ “ftp”12/GoogleCloudStorage(this is not GoogleDrive) \ “google cloud storage”13/GoogleDrive \ “drive”14/GooglePhotos \ “google photos”15/Hubic \ “hubic”16/JottaCloud \ “jottacloud”17/Koofr \ “koofr”18/LocalDisk \ “local”19/Mail.ru Cloud \ “mailru”20/Mega \ “mega”21/MicrosoftAzureBlobStorage \ “azureblob”22/MicrosoftOneDrive \ “onedrive”23/OpenDrive \ “opendrive”24/OpenstackSwift(RackspaceCloudFiles,MemsetMemstore,OVH) \ “swift”25/Pcloud \ “pcloud”26/Put.io \ “putio”27/QingCloudObjectStorage \ “qingstor”28/SSH/SFTPConnection \ “sftp”29/Transparently chunk/split large files \ “chunker”30/Union merges the contents of several remotes \ “union”31/Webdav \ “webdav”32/YandexDisk \ “yandex”33/ http Connection \ “http”34/ premiumize.me \ “premiumizeme”Storage>22**See help for onedrive backend at: https://rclone.org/onedrive/**MicrosoftAppClientIdLeave blank normally.Enter a string value.PressEnterfor the default(“”).client_id>MicrosoftAppClientSecretLeave blank normally.Enter a string value.PressEnterfor the default(“”).client_secret>Edit advanced config?(y/n)y)Yesn)Noy/n> nRemote configUse auto config? *Say Y if not sure *Say N if you are working on a remote or headless machiney)Yesn)Noy/n> yIf your browser doesn’t open automatically go to the following link: http://127.0.0.1:53682/auth?state=w-RJ_q2kZM-8ip50VOerAQLogin and authorize rclone for accessWaitingfor code…Got codeChoose a number from below, or type in an existing value 1/OneDrivePersonal or Business \ “onedrive” 2/RootSharepoint site \ “sharepoint” 3/Typein driveID \ “driveid” 4/TypeinSiteID \ “siteid” 5/Search a Sharepoint site \ “search”Your choice>1Found1 drives, please select the one you want to use:0:(personal) id=8e5cb089c5445907Chose drive to use:>0Found drive ‘root’ of type ‘personal’,URL: https://onedrive.live.com/?cid=8e5cb089c5445907Is that okay?y)Yesn)Noy/n> y2019/11/0210:38:14ERROR:Failed saving config “drive_id”=”8e5cb089c5445907″in section “carrot” of the config file: section ‘carrot’ not found2019/11/0210:38:14ERROR:Failed saving config “drive_type”=”personal”in section “carrot” of the config file: section ‘carrot’ not found——————–[carrot]type = onedrivetoken ={“access_token”:”**************”}drive_id = 8e5cb089c5445907drive_type = personal——————–y)Yes this isOKe)Edit this remoted)Delete this remotey/e/d> yCurrent remotes:NameType========carrot onedriverabbitmask onedrivee)Edit existing remoten)New remoted)Delete remoter)Rename remotec)Copy remotes)Set configuration passwordq)Quit confige/n/d/r/c/s/q> q

首先要说的就是没必要按照网上流传的那样一定要从Windows端将令牌生成,取消自认证然后手动粘贴,Linux平台的自认证完全可以。

挂载磁盘

自启动的原理其实就是自动挂载,但这里先手动挂载下梳理下流程。

mkdir /root/carrotrclone mount carrot: /root/carrot –copy-links –no-gzip-encoding –no-check-certificate –allow-other –allow-non-empty –umask 000

emmm,5G的个人云盘用来做私密文件存储,5T的白嫖盘用来存放堆叠的公开性文件和临时文件。

#解除挂载fusermount -qzu /root/carrot

rclone自启动

#!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHNAME_BIN=”reclone”### BEGIN INIT INFO# Provides: rclone# Required-Start: $all# Required-Stop: $all# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start rclone at boot time# Description: Enable rclone by daemon.### END INIT INFONAME=”” #rclone name名REMOTE=” #远程文件夹LOCAL=” #挂载地址Green_font_prefix=”\033[32m” && Red_font_prefix=”\033[31m” && Green_background_prefix=”\033[42;37m” && Red_background_prefix=”\033[41;37m” && Font_color_suffix=”\033[0m”Info=”${Green_font_prefix}[信息]${Font_color_suffix}”Error=”${Red_font_prefix}[错误]${Font_color_suffix}”RETVAL=0check_running(){ PID=”$(ps -C $NAME_BIN -o pid= |head -n1 |grep -o ‘[0-9]\{1,\}’)” if [[ ! -z ${PID} ]]; then return 0 else return 1 fi}do_start(){ check_running if [[ $? -eq 0 ]]; then echo -e “${Info} $NAME_BIN (PID ${PID}) 正在运行…” && exit 0 else fusermount -zuq $LOCAL >/dev/null 2>&1 mkdir -p $LOCAL /usr/bin/rclone mount $NAME:$REMOTE $LOCAL –copy-links –no-gzip-encoding –no-check-certificate –allow-other –allow-non-empty –umask 000 >/dev/null 2>&1 & sleep 2s check_running if [[ $? -eq 0 ]]; then echo -e “${Info} $NAME_BIN 启动成功 !” else echo -e “${Error} $NAME_BIN 启动失败 !” fi fi}do_stop(){ check_running if [[ $? -eq 0 ]]; then kill -9 ${PID} RETVAL=$? if [[ $RETVAL -eq 0 ]]; then echo -e “${Info} $NAME_BIN 停止成功 !” else echo -e “${Error} $NAME_BIN 停止失败 !” fi else echo -e “${Info} $NAME_BIN 未运行” RETVAL=1 fi fusermount -zuq $LOCAL >/dev/null 2>&1}do_status(){ check_running if [[ $? -eq 0 ]]; then echo -e “${Info} $NAME_BIN (PID $(echo ${PID})) 正在运行…” else echo -e “${Info} $NAME_BIN 未运行 !” RETVAL=1 fi}do_restart(){ do_stop do_start}case “$1” in start|stop|restart|status) do_$1 ;; *) echo “使用方法: $0 { start | stop | restart | status }” RETVAL=1 ;;esacexit $RETVAL

补充其中的三行,/代表的是OneDrive全盘。

NAME=”carrot” #rclone name名REMOTE=’/’ #远程文件夹LOCAL=’/root/carrot’ #挂载地址

mv rcloned /etc/init.d/rclonedchmod +x /etc/init.d/rclonedupdate-rc.d -f rcloned defaultsbash /etc/init.d/rcloned start

移除开机脚本:update-rc.d -f rcloned remove

假装END

果您使用的是root登录的vps,以上操作到此处就结束了,可能涉及到rclone服务问题,不支持同时定义两个,所以需要手动切换自动挂载脚本。

但果您使用的和我一样是parrot等高端血统的Linux,emmmm,可能要翻车了,普通用户登录并不会成功启动,因为其中的挂载命令需要root权限。

接着,你可以在登录的情况下手动启动脚本,不支持相互sudo,必须先切到su root,然后手动启动:

/etc/init.d/rcloned start

同样多个挂载切换需要先停掉这个,再切:

/etc/init.d/rcloned stop/etc/init.d/rclonedtmp start

我:???

唉,虽说parrot一族贵在折腾,这也忒low了。。。。

后来,通过修改 /etc/profile 测试,emmm,目测会翻车,因为命令会卡死!笔者物理机,方案果断通过。

最终!!还是自己写一个脚本手动拉起吧,关键就是在parrot上,这玩意儿有毒吧,挂载命令会卡住!导致sudo相互都有问题,所以我们还是已经创建了脚本,创建了onedrive.sh,切记切记,su root后再运行:

#!/bin/bash/etc/init.d/rcloned start && /etc/init.d/rclonedtmp start

脚本的逻辑是果进程中存在rclone,则不执行命令,返回rclone正在运行,因此对于多个挂载我们需要调整下逻辑,替换下第二个脚本:

#!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHNAME_BIN=”reclone”### BEGIN INIT INFO# Provides: rclone# Required-Start: $all# Required-Stop: $all# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start rclone at boot time# Description: Enable rclone by daemon.### END INIT INFONAME=”rabbitmask” #rclone name名REMOTE=’/’ #远程文件夹LOCAL=’/root/rabbitmask’ #挂载地址Green_font_prefix=”\033[32m” && Red_font_prefix=”\033[31m” && Green_background_prefix=”\033[42;37m” && Red_background_prefix=”\033[41;37m” && Font_color_suffix=”\033[0m”Info=”${Green_font_prefix}[信息]${Font_color_suffix}”Error=”${Red_font_prefix}[错误]${Font_color_suffix}”RETVAL=0check_running(){ PID=”$(ps -C $NAME_BIN -o pid= |tail -n1 |grep -o ‘[0-9]\{1,\}’)” if [[ ! -z ${PID} ]]; then return 0 else return 1 fi}do_start(){ fusermount -zuq $LOCAL >/dev/null 2>&1 mkdir -p $LOCAL /usr/bin/rclone mount $NAME:$REMOTE $LOCAL –copy-links –no-gzip-encoding –no-check-certificate –allow-other –allow-non-empty –umask 000 >/dev/null 2>&1 & sleep 2s check_running if [[ $? -eq 0 ]]; then echo -e “${Info} $NAME_BIN 启动成功 !” else echo -e “${Error} $NAME_BIN 启动失败 !” fi}do_stop(){ check_running if [[ $? -eq 0 ]]; then kill -9 ${PID} RETVAL=$? if [[ $RETVAL -eq 0 ]]; then echo -e “${Info} $NAME_BIN 停止成功 !” else echo -e “${Error} $NAME_BIN 停止失败 !” fi else echo -e “${Info} $NAME_BIN 未运行” RETVAL=1 fi fusermount -zuq $LOCAL >/dev/null 2>&1}do_status(){ check_running if [[ $? -eq 0 ]]; then echo -e “${Info} $NAME_BIN (PID $(echo ${PID})) 正在运行…” else echo -e “${Info} $NAME_BIN 未运行 !” RETVAL=1 fi}do_restart(){ do_stop do_start}case “$1” in start|stop|restart|status) do_$1 ;; *) echo “使用方法: $0 { start | stop | restart | status }” RETVAL=1 ;;esacexit $RETVAL

最终效果:

emmm,说实话,自启动处理我想了好多策略,依然不是很完美,细品还有很多不严谨的地方,导致的说依然没有绕过验证,对于普通用户而言仍为手动启动,嘤嘤嘤,欢迎研究员的小伙伴参与交流。

真·END

最终我们实现的效果就是以挂载到本地的方式,实现了跨平台的数据同步:

顺便一提,OneDrive和OneNote均支持安装和iOS,笔者也自然也启用了,基本实现个人的所有电子设备数据同步,吹爆Microsoft,棒呆!

About the Author

发表评论

邮箱地址不会被公开。 必填项已用*标注

You may also like these