rclone

安裝

依照官網下在binary檔進行安裝,apt下載的版本是比較舊的

設定

依照rclone config的指示進行設定

  1. 申請google OAuth client id,以便提高效能,使用 rclone config的時候會被詢問Option client_id.和Option client_secret.的時候可以填入

https://rclone.org/drive/#making-your-own-client-id

如果需要使用服務帳號

填入 JSON 金鑰檔案的完整路徑,例如:

1
/home/username/.config/rclone/service-account.json

或使用 ~ 代表家目錄:

1
~/rclone-service-account.json

jenhaoyang: 從哪裡取得service-account.json

GitHub Copilot: # 如何取得 Service Account JSON 金鑰檔案

Service Account JSON 金鑰檔案需要從 Google Cloud Platform (GCP) 建立和下載。以下是完整步驟:

建立service account步驟

rclone 在個人帳戶不要使用service account,因為沒辦法打開GSuite來設定權取Google drive API的權限

測試rclone連線

如果使用service account,必須把資料夾分享給service account的gmail帳號,因為他不能直接存取我們的google drive。另外也檢查的時候也必須要指定顯示與我們共用的資料夾,不然會看不到東西。

1
rclone ls google-remote: --drive-shared-with-me

https://ivonblog.com/posts/rclone-linux/

rclone mount

  1. 記得加上--daemon啟用背景執行
  2. --drive-shared-with-me也記得要加
    On Linux/macOS/FreeBSD start the mount like this, where /path/to/local/mount is an empty existing directory:
    1
    rclone mount remote:path/to/files /path/to/local/mount --drive-shared-with-me --daemon

rclone copy

rclone copy gdrive:backups/photos_backup /home/user/photos_restored

rclone copy 下載參數

核心參數建議

這是一個針對下載大量照片的 rclone copy 建議指令範本:

1
rclone copy --transfers=32 --checkers=64 --fast-list --progress remote:path/to/photos /local/path/to/photos

參數詳解與設定建議

  • --transfers=N

    • 作用:設定同時傳輸的檔案數量。這是提升大量小檔案下載速度最重要的參數。
    • 預設值:4
    • 建議設定:對於大量照片,您可以大幅提高此數值。建議從 1632 開始測試,如果您的網路頻寬和 CPU 效能允許,可以逐步增加,例如 64 或更高。需要注意的是,過高的數值可能會導致記憶體耗盡或被雲端服務商限速。
  • --checkers=N

    • 作用:設定並行檢查檔案的執行緒數量。在開始傳輸前,rclone 會檢查來源和目的地的檔案。增加此數值可以加快這個過程。
    • 預設值:8
    • 建議設定:此數值通常可以設定為 --transfers 的兩倍。例如,如果您設定 --transfers=32,可以將 --checkers 設定為 64。這有助於檢查程序快速完成,讓傳輸程序盡快開始。
  • --fast-list

    • 作用:這個參數會一次性列出遠端所有的檔案,而不是逐級遞迴掃描。對於包含大量檔案的目錄,這可以顯著減少列出檔案所需的時間。
    • 建議設定:在下載大量照片時,強烈建議啟用此參數。
  • --progress (-P)

    • 作用:顯示即時的傳輸進度,包括傳輸速度、預計剩餘時間和正在傳輸的檔案。這不會直接提升速度,但能幫助您監控傳輸狀況並判斷參數調整是否有效。

其他可選優化參數

  • --order-by string

    • 作用:控制檔案的傳輸順序。在某些情況下,混合傳輸大小檔案可能比隨機傳輸更有效率。
    • 建議設定:可以嘗試 --order-by "size,mixed,75",這會讓 rclone 優先處理 75% 的小檔案和 25% 的大檔案,有助於保持傳輸管道飽和。
  • --no-traverse

    • 作用:如果您只是要複製少量新檔案到一個已經很大的本地目錄,使用此參數可以避免掃描整個目標目錄,從而加快啟動速度。
    • 建議設定:僅適用於增量備份的場景。
  • --checksum (-c)

    • 作用:讓 rclone 不僅僅依賴檔案大小和修改時間,還會檢查檔案的校驗和 (checksum) 來判斷檔案是否相同。這會增加一些 CPU 負擔,但在確保資料完整性上更可靠。如果您的首要目標是速度,可以不加此參數。

如何找到最適合您的設定?

  1. 從建議值開始:使用 --transfers=32--checkers=64 作為起點。
  2. 監控效能:執行指令並加上 --progress 參數,觀察傳輸速度和穩定性。
  3. 逐步調整
    • 如果您的 CPU 使用率和網路頻寬都還很低,可以嘗試逐步增加 --transfers--checkers 的數值。
    • 如果開始出現大量錯誤訊息(例如 rateLimitExceededtimeout),或者速度不升反降,表示數值設定得太高,需要調降。

注意事項

  • 雲端服務商的限制:不同的雲端儲存(如 Google Drive, Dropbox, S3)對 API 的請求頻率有不同的限制。特別是 Google Drive,對於檔案的建立(這也間接影響下載)有每秒約 2-3 個檔案的限制。在這種情況下,即使瘋狂提高 --transfers 參數,速度也無法提升,甚至可能因觸發限制而變得更慢。
  • 硬體資源:較高的 --transfers--checkers 會消耗更多的記憶體和 CPU 資源。請確保您的電腦有足夠的資源來應付。
  • 打包檔案:如果照片檔案極小(例如都只有幾 KB),且數量極大(數十萬甚至百萬),最有效率的方式可能是在遠端將它們打包成一個大的壓縮檔(如 .zip 或 .tar),然後再下載這個單一的大檔案。 這可以完全繞過小檔案傳輸的延遲問題。

reclone設為service

啟動gui

rclone rcd –rc-web-gui –rc-web-gui-update –rc-no-auth

rclone的服務設定檔放在~/.config/systemd/user/底下

docker mount rclone資料夾

安裝fuse
sudo apt-get -y install fuse3
建立必要的資料夾

1
2
sudo mkdir -p /var/lib/docker-plugins/rclone/config
sudo mkdir -p /var/lib/docker-plugins/rclone/cache

安裝docker plugin

1
docker plugin install rclone/docker-volume-rclone:amd64 args="-v" --alias rclone --grant-all-permissions

必須先使用rclone config生出設定檔後,用rclone config file 找出rclone的設定檔位置,並且複製到/var/lib/docker-plugins/rclone/config

1
2
rclone config file
sudo cp ~/.config/rclone/rclone.conf /var/lib/docker-plugins/rclone/config

docker compose 範例,這裡以名稱為google-remote的relone 設定為例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: '3.8'

services:
myapp:
image: alpine
volumes:
- gdrive-volume:/data
command: ["sleep", "infinity"]

volumes:
gdrive-volume:
driver: rclone
driver_opts:
remote: "google-remote:"
allow_other: "true"
vfs-cache-mode: "full"
drive-shared-with-me: "true"

防火牆規則檢查

  1. 修改rclone config並且改掉token的過期時間讓rclone強制重新取得token
  2. 使用這個指令可以清楚看到rclone呼叫的url
    rclone about google-remote: -vv --dump headers

參考

https://rclone.org/commands/rclone_rcd/
https://gist.github.com/kabili207/2cd2d637e5c7617411a666d8d7e97101

fiftyone讀取dataset錯誤

  • 錯誤訊息
    1
    2
    {"t":{"$date":"2025-06-04T08:11:32.830Z"},"s":"I",  "c":"CONTROL",  "id":20697,   "ctx":"-","msg":"Renamed existing log file","attr":{"oldLogPath":"/home/iisi/.fiftyone/var/lib/mongo/log/mongo.log","newLogPath":"/home/iisi/.fiftyone/var/lib/mongo/log/mongo.log.2025-06-04T08-11-32"}}
    Subprocess ['/home/iisi/2005013/model_training/YOLO/venv/lib/python3.10/site-packages/fiftyone/db/bin/mongod', '--dbpath', '/home/iisi/.fiftyone/var/lib/mongo', '--logpath', '/home/iisi/.fiftyone/var/lib/mongo/log/mongo.log', '--port', '0', '--nounixsocket'] exited with error 100:

解法

https://docs.voxel51.com/user_guide/config.html#configuring-a-mongodb-connection

用自建的mongo db

You can achieve this by adding the following entry to your ~/.fiftyone/config.json file:
environment variable

1
export FIFTYONE_DATABASE_URI=mongodb://[username:password@]host[:port]

VSCode_CMake_GoogleTest

重點:

下面這兩行要放在最外面的 CMakeLists.txt 中,這樣才能在build資料夾啟動ctest

1
2
include(CTest)
enable_testing()

讓VSCode的Ctest可以下中斷點

參考:
https://stackoverflow.com/a/76447033/22299707

https://github.com/microsoft/vscode-cmake-tools/blob/defc0b5369c64467c3466b1cee3faba9f9633a6a/docs/debug-launch.md#debugging-tests

launch.json

1
2
3
4
5
6
7
8
9
{
"name": "(ctest) Launch",
"type": "cppdbg",
"cwd": "${cmake.testWorkingDirectory}",
"request": "launch",
"program": "${cmake.testProgram}",
"args": [ "${cmake.testArgs}" ],
// other options...
}

參考:
https://github.com/esweet431/box2d-lite/blob/vs-launch/CMakePresets.json

cmake google test配置

範例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
find_package(Threads REQUIRED)


include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 52eb8108c5bdec04579160ae17225d66034bd723 # release-1.17.0
)
FetchContent_MakeAvailable(googletest)
enable_testing()

# Create a libgmock target to be used as a dependency by test programs

add_subdirectory(testplate)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
include(GoogleTest)
file(GLOB SRCS *.cpp)
add_executable(testplate ${SRCS})


target_link_libraries(testplate
gtest_main
libtestplate
)

gtest_add_tests(TARGET testplate
TEST_SUFFIX .noArgs
TEST_LIST noArgsTests
)

#gtest_add_tests(TARGET testplate
# EXTRA_ARGS --someArg someValue
# TEST_SUFFIX .withArgs
# TEST_LIST withArgsTests
#)

set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10)
#set_tests_properties(${withArgsTests} PROPERTIES TIMEOUT 20)

參考:
https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package

https://cmake.org/cmake/help/v3.31/module/GoogleTest.html#command:gtest_add_tests

Ubuntu加入WindowsAD

查詢AD server
文件SSSD
https://documentation.ubuntu.com/server/how-to/sssd/with-active-directory/#sssd-with-active-directory

echo %logonserver%
nslookup

範例:
Microsoft Windows [Version 10.0.19045.5011]
(c) Microsoft Corporation. All rights reserved.

C:\Users\2005013>echo %logonserver%
\IEDC022

C:\Users\2005013>nslookup \IEDC022
Server: DNS221.iead.local
Address: 192.168.16.44

Name: IEDC022.iead.local
Address: 192.168.16.32

C:\Users\2005013>

確保 DNS 配置正確

將 AD 的 DNS 伺服器地址添加到 nameserver,例如:

1
2
nameserver <AD_DNS_SERVER_IP>
search <AD_DOMAIN>

範例
nameserver 192.168.11.32
search iiiid.local

GPT

GitHub Copilot: 在你的情境下,使用 SSSD 整合 Ubuntu Server 與 Windows Active Directory (AD) 是最適合的選擇。SSSD 提供了與 AD 的良好整合,並且支援 Linux 系統的身份驗證和授權,讓擁有 AD 帳號的用戶可以登入 Ubuntu Server。


為什麼選擇 SSSD?

  1. 跨平台支援:SSSD 是 Linux 上的身份驗證解決方案,專為與 AD 整合設計。
  2. 簡化管理:SSSD 支援 Kerberos 和 LDAP,能直接與 AD 通信,並且可以緩存身份驗證數據,減少對 AD 的依賴。
  3. 靈活性:除了身份驗證,SSSD 還支援基於 AD 群組的授權控制。
  4. 穩定性:SSSD 是 Ubuntu 官方推薦的解決方案,並且有良好的社群支持。

實現步驟

以下是將 Ubuntu Server 加入 Windows AD 並允許 AD 用戶登入的基本步驟:

1. 安裝必要的套件

在 Ubuntu Server 上安裝 SSSD 和相關工具:

1
2
sudo apt update
sudo apt install sssd-ad sssd-tools realmd adcli krb5-user packagekit

2. 確保 DNS 配置正確

AD 的身份驗證依賴正確的 DNS 設定,請確保 Ubuntu Server 能解析 AD 網域名稱:

1
sudo nano /etc/resolv.conf

將 AD 的 DNS 伺服器地址添加到 nameserver,例如:

1
2
nameserver <AD_DNS_SERVER_IP>
search <AD_DOMAIN>

3. 加入 AD 網域

使用 realm 工具將 Ubuntu Server 加入 AD 網域:

1
sudo realm join --user=<AD_ADMIN_USERNAME> <AD_DOMAIN>

系統會提示輸入 AD 管理員的密碼,成功後會自動配置 SSSD。

4. 驗證網域加入狀態

確認 Ubuntu Server 已成功加入 AD:

1
realm list

你應該能看到 AD 網域的相關資訊。

5. 配置 SSSD

檢查或修改 SSSD 配置檔案 /etc/sssd/sssd.conf,確保內容類似以下:

1
2
3
4
5
6
7
8
9
[sssd]
services = nss, pam
domains = <AD_DOMAIN>

[domain/<AD_DOMAIN>]
id_provider = ad
access_provider = ad
override_homedir = /home/%d/%u
default_shell = /bin/bash

保存後,重啟 SSSD:

1
sudo systemctl restart sssd

6. 測試 AD 用戶登入

嘗試使用 AD 用戶登入 Ubuntu Server:

1
ssh <AD_USERNAME>@<UBUNTU_SERVER_IP>

如果配置正確,AD 用戶應該能成功登入。

7. 可選:限制登入權限

如果你希望只允許特定 AD 群組的用戶登入,可以在 /etc/sssd/sssd.conf 中添加:

1
2
access_provider = ad
ad_access_filter = (memberOf=CN=<GROUP_NAME>,OU=<OU_NAME>,DC=<DOMAIN>,DC=<COM>)

重啟 SSSD 後,只有屬於該群組的用戶才能登入。


結論

使用 SSSD 是將 Ubuntu Server 加入 Windows AD 的最佳方式,因為它提供了穩定、高效且靈活的身份驗證解決方案。完成上述配置後,AD 用戶即可使用其帳號登入 Ubuntu Server,並且可以根據需求進一步限制登入權限。

參考:

https://poweradm.com/join-ubuntu-debian-active-directory-domain/

使用gst-shark

安裝

git clone https://github.com/RidgeRun/gst-shark/
apt install octave epstool babeltrace gtk-doc-tools
apt install graphviz libgraphviz-dev

編譯

sudo apt install python3 python3-pip ninja-build
pip3 install –user meson
sudo cp ~/.local/bin/meson /usr/bin/meson

meson builddir –prefix /usr/
ninja -C builddir

安裝

ninja install -C builddir

如果有更動gst-shark的程式碼,則需要重新編譯安裝

ninja -C builddir
ninja install -C builddir

在deepstream使用gst-shark的時候會需要修改以下程式碼並且重新編譯,以免出錯
gst_shark_tracer_hook_pad_push_pre,要檢查GST_OBJECT_PARENT的結果是不是NULL,是就return,修改如下

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
/* My hooks */
static void
gst_shark_tracer_hook_pad_push_pre (GObject * object, GstClockTime ts,
GstPad * pad, GstBuffer * buffer)
{
GstSharkTracer *self = GST_SHARK_TRACER (object);
GstSharkTracerPrivate *priv = GST_SHARK_TRACER_PRIVATE (self);
GCallback hook;
const gchar *elname;

GstObject* gst_obj = GST_OBJECT_PARENT (pad);
if (gst_obj == NULL){
return;
}
elname = GST_OBJECT_NAME (gst_obj);
if (FALSE == gst_shark_tracer_element_is_filtered (self, elname)) {
return;
}

hook = g_hash_table_lookup (priv->hooks, "pad-push-pre");
g_return_if_fail (hook);

((void (*)(GObject *, GstClockTime, GstPad *, GstBuffer *)) hook) (object, ts,
pad, buffer);
}

使用

export GST_SHARK_LOCATION=/root/apps/iisi-ds64/iisi-ds63/my_exp/shark
export GST_DEBUG=”GST_TRACER:7”
export GST_TRACERS=”queuelevel”

執行deepstream,並且用q結束程式,確認shark底下的metadata有資料

下面是產生圖片的方式

cd gst-shark/scripts/graphics

Display the plot on the screen

./gstshark-plot /root/apps/iisi-ds64/iisi-ds63/my_exp/shark -p

Save the plot to a PDF

./gstshark-plot /root/apps/iisi-ds64/iisi-ds63/my_exp/shark -s pdf

Save the plot to a PNG

./gstshark-plot /root/apps/iisi-ds64/iisi-ds63/my_exp/shark -s png

gstreamer使用gdb的方法

git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git
cd gstreamer/
git checkout 1.20.3

pip3 install –user meson

meson setup builddir

ninja -C builddir

測試gst環境成功
https://www.collabora.com/news-and-blog/blog/2020/03/19/getting-started-with-gstreamer-gst-build/
1.在程式subprojects/gst-plugins-base/gst/videotestsrc/gstvideotestsrc.c中加料
在gst_video_test_src_start()中加上,故意讓程式報錯跳出

1
GST_ERROR_OBJECT (src, "Starting to debug videotestsrc, is there an error ?");

2.ninja -C build重新編譯程式,可以注意到這次編譯只會編譯被更新的檔案
3.執行GST_DEBUG=videotestsrc:1 gst-launch-1.0 videotestsrc num-buffers=1 ! fakevideosink,並出現錯誤,表示測試成功

1
2
3
4
5
6
7
8
9
10
11
12
Setting pipeline to PAUSED ...
0:00:00.225273663 21743 0x565528ab7100 ERROR videotestsrc gstvideotestsrc.c:1216:gst_video_test_src_start: Starting to debug videotestsrc, is there an error ?
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:00.033464391
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ..

使用gst環境(類似python的venv)
python3 gst-env.py
以下連結說明有更新的環境變數
https://gstreamer.freedesktop.org/documentation/installing/building-from-source-using-meson.html#how-does-it-work

此時許多環境變數被自動設置,包含pkg-config也被設置,可以用pkg-config –cflags gstreamer-1.0檢查gstreamer的路徑,如此一來讓cmake編譯也可以連結到自行編譯的程式,並且包含gdb下中斷點需要的資訊

把deepstream的gst-plugin的變數加進來,這樣才找的到deepstream的plugin
export GST_PLUGIN_PATH=/opt/nvidia/deepstream/deepstream/lib/gst-plugins:$GST_PLUGIN_PATH

gdb下中斷點
gst_element_factory_make

vscode要在debug的那一個terimal執行gst-env.py才能讓中斷點停在gstreamer的程式上面