問題


自從使用Nextcloud以來,一直沒有遇到太大的問題,但由於我租用的 VPS 只有區區 60GB 的 SSD 容量(用 SSD 當儲存碟有點奢侈 XD),為了擁有更大的儲存空間,懶懶就將壞腦筋動到雲端硬碟上。

然而,當我使用 Rclone 掛載 OneDrive E5 雲端硬碟後,卻發現若在主機端直接上傳檔案,Nextcloud 這端卻無法同步顯示上傳的檔案。以下是我處理的步驟:

教學


可以先以下列指令,試著刷新檔案清單

sudo -u www-data php7.4 /var/www/nextcloud/occ files:scan --all
注意事項
  1. www-data 部分為使用者名稱
  2. php7.4 部分視你的php版本名稱而定 e.g. php php7.4
  3. /var/www/nextcloud/occ 部分為nextcloud資料夾路徑

加入crontab工作


確認上述步驟成功後,使用crontab工作排程實現自動刷新

sudo -i #切換到root  
crontab -u www-data -e #編輯crontab工作排程(www-data為使用者名稱)

最下方新增標註部分,其中”/10“為10分鐘刷新一次,可自由選擇刷新時間

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
*/5 * * * * php7.4 -f /var/www/nextcloud/cron.php
*/10 * * * * php7.4 /var/www/nextcloud/occ files:scan --all #新增此列

接著存檔就完成囉~~

參考資料


1.linux使用rclone挂载onedrive作为挂载盘
2.nextcloud挂载onedrive作为外接盘
3.Using the occ command