部署trilium web云服务
使用云服务器部署trilium web并利用rclone将数据同步到onedrive
部署trilium
因为我使用的是中文版,所以我并没有使用官方版GitHub - zadam/trilium: Build your personal knowledge base with Trilium Notes
而是使用了 GitHub - Nriver/trilium-translation: Translation for Trilium Notes. Trilium Notes 中文适配, 体验优化
docker启动
docker-compose.yml
version: '3'
services:
trilium-cn:
image: nriver/trilium-cn
restart: always
ports:
- "8080:8080"
volumes:
# 把同文件夹下的 trilium-data 目录映射到容器内
- ./trilium-data:/root/trilium-data
environment:
# 环境变量表示容器内笔记数据的存储路径
- TRILIUM_DATA_DIR=/root/trilium-data
docker-compose up -d
nginx转发
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:8080;
proxy_read_timeout 90;
}
rclone备份
配置rclone
下载rclone
apt install rclone
使用window获得token Microsoft OneDrive (rclone.org)
获取长期token参考官方文档
Microsoft OneDrive (rclone.org)
To create your own Client ID, please follow these steps:
- Open https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade and then click
New registration.- Enter a name for your app, choose account type
Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox), selectWebinRedirect URI, then type (do not copy and paste)http://localhost:53682/and click Register. Copy and keep theApplication (client) IDunder the app name for later use.- Under
manageselectCertificates & secrets, clickNew client secret. Enter a description (can be anything) and setExpiresto 24 months. Copy and keep that secret Value for later use (you won’t be able to see this value afterwards).- Under
manageselectAPI permissions, clickAdd a permissionand selectMicrosoft Graphthen selectdelegated permissions.- Search and select the following permissions:
Files.Read,Files.ReadWrite,Files.Read.All,Files.ReadWrite.All,offline_access,User.ReadandSites.Read.All(if custom access scopes are configured, select the permissions accordingly). Once selected clickAdd permissionsat the bottom.Now the application is complete. Run
rclone configto create or edit a OneDrive remote. Supply the app ID and password as Client ID and Secret, respectively. rclone will walk you through the remaining steps.
rclone config file #获取rclone的配置文件,上传至linux服务器
备份脚本
date1=$(date --date='6 hour ago')
date2=$(stat -c %y /var/trilium-data/document.db)
echo "当前时间为 -> $(date)" >> /var/shell/backup.log
echo "document.db修改时间为 $date2" >> /var/shell/backup.log
t1=`date -d "$date1" +%s`
t2=`date -d "$date2" +%s`
if [ $t2 -gt $t1 ]; then
echo "开始备份..." >> /var/shell/backup.log
zip -q -r /var/shell/back_up.zip /var/trilium-data/
rclone sync /var/shell/back_up.zip onedrive:trilium-data/ >> /var/shell/backup.log
echo "备份成功" >> /var/shell/backup.log
else
echo "无需备份" >> /var/shell/backup.log
fi
echo -e "\n" >> /var/shell/backup.log
使用 crontab -e 进行定时任务配置
0 6,12,18,24 * * * sh /var/shell/backup.sh
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 zeropava!
评论







