linux与onedrive间同步/备份

参照博客github项目

安装依赖(针对centos)

1
2
3
4
5
yum groupinstall 'Development Tools' -y
yum install libcurl-devel -y
yum install sqlite-devel -y
yum install libnotify-devel -y
curl -fsS https://dlang.org/install.sh bash -s dmd

安装后返回信息 执行source ~/dlang/dmd-2.090.0/activate激活环境。

安装客户端

1
2
3
4
5
git clone https://github.com/abraunegg/onedrive.git
cd onedrive
./configure
make clean; make;
sudo make install

认证

执行onedrive命令 复制链接,输入浏览器登录账号进行授权,再将授权后的链接地址复制到SSH客户端运行。

同步

显示参数

1
onedrive --display-config

测试参数

1
onedrive --synchronize --verbose --dry-run

展示执行同步命令即将发生的。 Note: —dry-run can only be used with —synchronize. It cannot be used with —monitor and will be ignored.

执行同步(默认)

默认会将onedrive的所有文件下到/root/onedrive中。

1
onedrive --synchronize

同步某个文件夹

只同步OndDrive某文件夹到本地

1
onedrive --synchronize --single-directory '<dir_name>'

单向—只执行下载同步

1
onedrive --synchronize --download-only 

单向—只执行上传同步

1
onedrive --synchronize --upload-only

部分参数说明

配置文件 在/root/.config/onedrive中 执行cd /root/.config/onedrive,新建配置文件touch config。然后将下面默认配置内容粘贴进去。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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 = "45"
# 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"
# force_http_2 = "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 = "10"
# sync_root_files = "false"
# classify_as_big_delete = "1000"
# user_agent = ""

sync_dir

sync_dir 指定OneDrive中的文件同步到本地文件的位置 若修改sync_dir需在同步时,在原命令后加--resync,如onedrive --synchronize --resync

skip_dir

skip_dir同步时跳过本地的某些文件夹。

skip_file

skip_file同步时跳过本地的某些文件 注意:修改skip_dirskip_file都是相对sync_dir而言的,并且修改后同步,要在原命令后加--resync。 具体见这里

卸载客户端

在下载的onedrive目录下执行命令

1
2
sudo make uninstall
rm -rf ~/.config/onedrive

onedrive帮助

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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 authorization via two files passed in as ARG in the format `authUrl:responseUrl`
The authorization URL is written to the `authUrl`, then onedrive waits for the file `responseUrl`
to be present, and reads the response from that file.
--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.
--confdir ARG
Set the directory used to store the configuration files
--create-directory ARG
Create a directory on OneDrive - no sync will be performed.
--debug-https
Debug OneDrive HTTPS communication.
--destination-directory ARG
Destination directory for renamed or move on OneDrive - no sync will be performed.
--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
Only download remote changes
--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-1.1
Force the use of HTTP/1.1 for all operations (DEPRECIATED)
--force-http-2
Force the use of HTTP/2 for all operations where applicable
--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.
--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
--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
--print-token
Print the access token, useful for debugging
--remove-directory ARG
Remove a directory on OneDrive - no sync will be performed.
--resync
Forget the last saved state, perform a full sync
--single-directory ARG
Specify a single local directory within the OneDrive root to sync.
--skip-dir
Skip any directories that match this pattern from syncing
--skip-dot-files
Skip dot files and folders from syncing
--skip-file ARG
Skip any files that match this pattern from syncing
--skip-size
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.
--sync-root-files
Sync all files in sync_dir root when using sync_list.
--syncdir ARG
Specify the local directory used for synchronization to OneDrive
--synchronize
Perform a synchronization
--upload-only
Only upload to OneDrive, do not sync changes from OneDrive locally
--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