lamp 1. lamp簡介 lamp,其實就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一組動態網站或者伺服器的開源軟體 LAMP指的是Linux(操作系統)、Apache(HTTP伺服器)、MySQL(也指MariaDB,資料庫軟體)和PHP(有時也 ...
項目地址: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 [email protected]
,這裡的dyson
需要改成大家自己的用戶名 - 運行
systemctl start [email protected]
,dyson
同上。此時系統服務就設置好了 - 運行
systemctl status [email protected]
,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