---
# System prepended metadata

title: LXC Rclone Watchexec 上傳PVE備份
tags: [pve, rclone, watchexec, lxc, backup, upload]

---

透過Watchexec監聽宿主機備份目錄, 當有新備份檔時, 利用Rclone進行上傳
## 1. 創建LXC
![](https://hackmd.io/_uploads/ry-DKyJ9n.png)
![](https://hackmd.io/_uploads/By_Oty192.png)
![](https://hackmd.io/_uploads/Syt2Kk1qn.png)
![](https://hackmd.io/_uploads/SkZ0Y1192.png)
![](https://hackmd.io/_uploads/BJKkc1k52.png)
![](https://hackmd.io/_uploads/Sy0xcJ192.png)

## 2. 編輯LXC配置, 掛載PVE備份目錄
- 添加 Mount Point( mp0: 主機路徑,mp=容器路徑 )
```shell
$ nano /etc/pve/lxc/110.conf

mp0: /var/lib/vz/dump,mp=/mnt/dump
```

## 3. RCLONE
- 安裝([官方安裝文檔](https://rclone.org/install/))
```shell
$ sudo -v ; curl https://rclone.org/install.sh | sudo bash
```
- 守護進程, 開機自啟
```shell
$ nano /etc/systemd/system/rcloneui.service

[Unit]
Description=RCLONE UI

[Service]
Type=simple
User=root
ExecStart=/usr/bin/sudo /bin/bash -lc 'rclone rcd --rc-web-gui --rc-addr :5572 --rc-user=admin --rc-pass=admin'

[Install]
WantedBy=multi-user.target
```
```shell
$ systemctl enable --now rcloneui
```
- 透過WebUI或Cli 進行配置
http://localhost:5572   或  rclone config
建議加密後再上傳(先配置完,再創一個選14加密+設定密碼)
## 4. Watchexec
- 安裝
```shell
$ curl -fsSL https://apt.cli.rs/pubkey.asc | sudo tee -a /usr/share/keyrings/rust-tools.asc
$ curl -fsSL https://apt.cli.rs/rust-tools.list | sudo tee /etc/apt/sources.list.d/rust-tools.list
$ sudo apt update
$ sudo apt install watchexec-cli
```
- 測試, 監聽備份目錄, 僅處理備份檔案附檔名 zst,gz,lzo
```shell
watchexec --on-busy-update=queue -e zst,gz,lzo -w /mnt/dump rclone copy /mnt/dump remote:/pve-backup --include "*.{zst,gz,lzo}" --d-run --ignore-existing --verbose
```
- 守護進程
```shell
$ nano /etc/systemd/system/watchbak.service

[Unit]
Description=Watchexec Backup

[Service]
Type=simple
User=root
ExecStart=/usr/bin/sudo /bin/bash -lc 'watchexec --on-busy-update=queue -e zst,gz,lzo -w /mnt/dump rclone copy /mnt/dump remote:/pve-backup --include "*.{zst,gz,lzo}" --ignore-existing --verbose'

[Install]
WantedBy=multi-user.target
```
```shell
$ systemctl enable --now watchbak
```
## 5. 操作備份
- 在PVE介面上, 執行備份, 備份完成後
- 查看LXC日誌, 確認是否觸發並且上傳中
```shell
$ journalctl -f -u watchbak
```
## 6. 還原
- LXC
CT_ID: 108
```shell
$ pct restore 108 vzdump-lxc-108-20xxx.tar.gz --storage=local-lvm
```
- VM