- A+
项目地址:https://github.com/abraunegg/onedrive
笔者系统版本:Ubuntu 20.04
本文将介绍的主要内容:在Ubuntu20.04版本下下载、安装onedrive,并完成对该软件的基本设置,包括:修改保存位置、跳过onedrive下特定文件夹、开启日志、将onedrive设为系统服务
下载与安装
前往页面https://github.com/abraunegg/onedrive/blob/master/docs/ubuntu-package-install.md
查看对应指令,系统版本和我一样的同学可以直接复制下列指令完成下载与安装
wget -qO - https://download.opensuse.org/repositories/home:/npreining:/debian-ubuntu-onedrive/xUbuntu_20.04/Release.key | sudo apt-key add - echo 'deb https://download.opensuse.org/repositories/home:/npreining:/debian-ubuntu-onedrive/xUbuntu_20.04/ ./' | sudo tee /etc/apt/sources.list.d/onedrive.list sudo apt-get update sudo apt install onedrive
配置
本文主要完成以下配置
- onedrive授权
- 下载、修改配置文件
- 开始同步
- 将onedrive设置成系统服务
项目给出的配置教程文件地址如下,有需要的同学可以查看其他未提及的用法与配置
https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.md
授权
-
推荐连接梯子后操作,但非必须
-
打开命令行,输入
onedrive
-
在命令行中的
url
按住ctrl
后左键单击打开。注意此时不要关闭打开的命令行 -
在网页中输入自己的帐号密码,随后会页面跳转至一个空白页。
-
复制空白页的地址,回到命令行并粘贴上一部复制的地址
注意:这一步可能会连接失败,各位多尝试几次。
下载、编辑配置文件
下载
- 在用户目录下创建文件夹
mkdir -p ~/.config/onedrive
- 下载配置文件:
wget https://raw.githubusercontent.com/abraunegg/onedrive/master/config -O ~/.config/onedrive/config
配置文件具体内容如下:
# Configuration for OneDrive Linux Client # This file contains the list of supported configuration fields # with their default values. # All values need to be enclosed in quotes # When changing a config option below, remove the '#' from the start of the line # For explanations of all config options below see docs/USAGE.md or the man page. # # sync_dir = "~/OneDrive" # skip_file = "~*|.~*|*.tmp" # monitor_interval = "300" # skip_dir = "" # log_dir = "/var/log/onedrive/" # drive_id = "" # upload_only = "false" # check_nomount = "false" # check_nosync = "false" # download_only = "false" # disable_notifications = "false" # disable_upload_validation = "false" # enable_logging = "false" # force_http_11 = "false" # local_first = "false" # no_remote_delete = "false" # skip_symlinks = "false" # debug_https = "false" # skip_dotfiles = "false" # dry_run = "false" # min_notify_changes = "5" # monitor_log_frequency = "5" # monitor_fullscan_frequency = "12" # sync_root_files = "false" # classify_as_big_delete = "1000" # user_agent = "" # remove_source_files = "false" # skip_dir_strict_match = "false" # application_id = "" # resync = "false" # resync_auth = "false" # bypass_data_preservation = "false" # azure_ad_endpoint = "" # azure_tenant_id = "common" # sync_business_shared_folders = "false" # sync_dir_permissions = "700" # sync_file_permissions = "600" # rate_limit = "131072" # operation_timeout = "3600" # webhook_enabled = "false" # webhook_public_url = "" # webhook_listening_host = "" # webhook_listening_port = "8888" # webhook_expiration_interval = "86400" # webhook_renewal_interval = "43200" # space_reservation = "50"
编辑配置
配置方面,我主要修改了:
- 同步在linux上的存储位置
- 跳过一些在onedrive上,但不想保存在linux上的文件
- 开启日志并修改日志存储位置
其他具体的各项设置可以前往下列地址查看帮助
https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.md
修改存储位置
-
onedrive默认的保存位置为
~/OneDrive
,也可以修改保存位置。方法如下 -
用任意编辑器打开文件:
~/.config/onedrive/config
-
找到项
sync_dir
,删去其前的#
-
这里笔者想要存储在本地目录
~/Documents
下,故将该项改成了sync_dir = "~/Documents"
,大家按需修改即可
跳过onedrive中的特定目录
- 笔者用linux学习记录更多一些,而onedrive中一些内容与学习记录这一目的无关。这时,为了节省空间,我们就需要跳过对这些与学习无关文件夹的同步了。方法如下
- 笔者onedrive的根目录下有三个文件夹:
attach
、documents
、pictures
,而我并不需要对pictures
这一文件夹同步 - 用任意编辑器打开文件:
~/.config/onedrive/config
- 找到项
skip_dir
,删去其前的#
- 将该项改成
skip_dir = "pictures"
注:
- 文件夹可以有多个,其间用
|
分隔 - 文件夹可以定位至子文件夹如:
pictures/arch1
开启日志并修改日志存储位置
- 笔者想要存储的日志位置为:
~/.config/onedrive
- 打开配置文件
- 找到项
log_dir
,删去其前的#
- 将该项改成
log_dir = "~/.config/onedrive/"
,特别注意这里要确保在文件末尾加上/
,否则无法正确识别
开始同步
- 同步往往会因为
GFW
,导致连接出错,建议在联好梯子后运行 - 在正式运行前,可以先输入下列命令看看运行结果而不对系统产生变化,即
dry run
。
onedrive --dry-run --synchronize
命令会因为GFW而连接出错,我在配置的过程中就出现了两种错误,但在尝试了三次后就正常了
- 如果
dry run
符合你的预期,那么便可以正式运行啦,输入下列命令。
onedrive --synchronize --verbose --resync --local-first
- 运行完后,云端文件便保存至本地啦
将onedrive设置成系统服务
官方的帮助文件中给出了三种方法,我采用的是通过systemd 以非root用户身份运行OneDrive服务
,这种方法的好处是规避了root用户创建的文件权限的问题
- 此方法需要知晓root的密码,以及普通用户的用户名
- 运行
onedrive --synchronize --verbose
,查看是否正常运行 - 运行
su
,切换为root - 运行
systemctl enable onedrive@dyson.service
,这里的dyson
需要改成大家自己的用户名 - 运行
systemctl start onedrive@dyson.service
,dyson
同上。此时系统服务就设置好了 - 运行
systemctl status onedrive@dyson.service
,dyson
同上。这条命令用于查看是否正确运行 - 运行
exit
,回退至普通用户
附:onedrive --help
Configuration file successfully loaded OneDrive - a client for OneDrive Cloud Services Usage: onedrive [options] --synchronize Do a one time synchronization onedrive [options] --monitor Monitor filesystem and sync regularly onedrive [options] --display-config Display the currently used configuration onedrive [options] --display-sync-status Query OneDrive service and report on pending changes onedrive -h | --help Show this help screen onedrive --version Show version Options: --auth-files ARG Perform authentication not via interactive dialog but via files read/writes to these files. --auth-response ARG Perform authentication not via interactive dialog but via providing the response url directly. --check-for-nomount Check for the presence of .nosync in the syncdir root. If found, do not perform sync. --check-for-nosync Check for the presence of .nosync in each directory. If found, skip directory from sync. --classify-as-big-delete Number of children in a path that is locally removed which will be classified as a 'big data delete' --confdir ARG Set the directory used to store the configuration files --create-directory ARG Create a directory on OneDrive - no sync will be performed. --create-share-link ARG Create a shareable link for an existing file on OneDrive --debug-https Debug OneDrive HTTPS communication. --destination-directory ARG Destination directory for renamed or move on OneDrive - no sync will be performed. --disable-download-validation Disable download validation when downloading from OneDrive --disable-notifications Do not use desktop notifications in monitor mode. --disable-upload-validation Disable upload validation when uploading to OneDrive --display-config Display what options the client will use as currently configured - no sync will be performed. --display-sync-status Display the sync status of the client - no sync will be performed. --download-only Replicate the OneDrive online state locally, by only downloading changes from OneDrive. Do not upload local changes to OneDrive. --dry-run Perform a trial sync with no changes made --enable-logging Enable client activity to a separate log file --force Force the deletion of data when a 'big delete' is detected --force-http-11 Force the use of HTTP 1.1 for all operations --force-sync Force a synchronization of a specific folder, only when using --synchronize --single-directory and ignore all non-default skip_dir and skip_file rules --get-O365-drive-id ARG Query and return the Office 365 Drive ID for a given Office 365 SharePoint Shared Library --get-file-link ARG Display the file link of a synced file --help -h This help information. --list-shared-folders List OneDrive Business Shared Folders --local-first Synchronize from the local directory source first, before downloading changes from OneDrive. --log-dir ARG Directory where logging output is saved to, needs to end with a slash. --logout Logout the current user --min-notify-changes ARG Minimum number of pending incoming changes necessary to trigger a desktop notification --modified-by ARG Display the last modified by details of a given path --monitor -m Keep monitoring for local and remote changes --monitor-fullscan-frequency ARG Number of sync runs before performing a full local scan of the synced directory --monitor-interval ARG Number of seconds by which each sync operation is undertaken when idle under monitor mode. --monitor-log-frequency ARG Frequency of logging in monitor mode --no-remote-delete Do not delete local file 'deletes' from OneDrive when using --upload-only --operation-timeout Maximum amount of time (in seconds) an operation is allowed to take --print-token Print the access token, useful for debugging --reauth Reauthenticate the client with OneDrive --remove-directory ARG Remove a directory on OneDrive - no sync will be performed. --remove-source-files Remove source file after successful transfer to OneDrive when using --upload-only --resync Forget the last saved state, perform a full sync --resync-auth Approve the use of performing a --resync action --single-directory ARG Specify a single local directory within the OneDrive root to sync. --skip-dir ARG Skip any directories that match this pattern from syncing --skip-dir-strict-match When matching skip_dir directories, only match explicit matches --skip-dot-files Skip dot files and folders from syncing --skip-file ARG Skip any files that match this pattern from syncing --skip-size ARG Skip new files larger than this size (in MB) --skip-symlinks Skip syncing of symlinks --source-directory ARG Source directory to rename or move on OneDrive - no sync will be performed. --space-reservation ARG The amount of disk space to reserve (in MB) to avoid 100% disk space utilisation --sync-root-files Sync all files in sync_dir root when using sync_list. --sync-shared-folders Sync OneDrive Business Shared Folders --syncdir ARG Specify the local directory used for synchronization to OneDrive --synchronize Perform a synchronization --upload-only Replicate the locally configured sync_dir state to OneDrive, by only uploading local changes to OneDrive. Do not download changes from OneDrive. --user-agent ARG Specify a User Agent string to the http client --verbose -v+ Print more details, useful for debugging (repeat for extra debugging) --version Print the version and exit