vault backup: 2024-02-17 23:16:21

This commit is contained in:
2024-02-17 23:16:21 +08:00
parent d7f574153d
commit 2021ab7180
56 changed files with 3 additions and 16 deletions

View File

@@ -0,0 +1,109 @@
## 安裝 Watchtower
```shell
docker pull Watchtower
```
## 使用方法
```shell
docker run --detach \
--name watchtower \
--volume /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower
```
使用剛剛的方法會拉取最新鏡像,但並不會自動刪除舊有鏡像,時間一長就會佔用很大空間,這裡可以使用 `--cleanup` 選項,在更新完舊容器之後自動刪除舊鏡像
```shell
docker run -d \
--name watchtower \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup
```
### 或使用 docke-compose.yml
```yml
version: "3"
services:
watchtower:
image: containrrr/watchtower
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 86400 --cleanup
```
### 設置自動更新檢測頻率
Watchtower 默認是每 5min 檢測一次,如果需要更改週期,可以使用 `--interval``-i` 選項
如設定每小時檢測一次:
```shell
docker run -d \
--name watchtower \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup \
-i 3600
```
`-i 3600`:這裡的 `3600` 是設置的時間週期,單位是**秒** `3600` 即 1 小時
### 指定更新檢測時間
除了設置頻率,還可以使用 `--schedule``-s` 選項指定時間 如指定每天 UTC+8 時間凌晨 3 點更新。
```shell
docker run -d \
--name watchtower \
--restart always \
-e TZ=Asia/Taipei \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup \
-s "0 0 3 * * *"
```
這裡的執行時間為 UTC 時間,如果不指定時區,會比台北的 UTC+8:00 時間晚 8 小時
### 制定需要更新的容器
如果不想更新所有容器,可以設置指定的容器進行更新
`nginx``netdata` 這兩個容器舉例:
```shell
docker run -d \
--name watchtower \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup \
nginx netdata
```
這裡指定的容器只需要填寫**容器名**,而不是填寫該容器的**鏡像名**
## 手動更新
如果不想在使用容器時被自動更新打斷,可以使用 Watchtower 進行手動更新
由於是手動更新Watchtower 只需要用到一次,可以添加 `--rm``--run-once` 參數,在更新完之後過河拆橋
### 手動更新所有容器
```shell
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup \
--run-once
```
## 手動更新指定容器
繼續以 `nginx``netdata` 這兩個容器舉例
```shell
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup \
--run-once \
nginx netdata
```
## 參考
- [使用Watchtower自動更新Docker鏡像和容器 - Docker容器 - 計算機 | 🧂 = 鹽🧂的記事本 = ( ´∀`)ヵヵヵ](https://www.sio.moe/2021/12/18/computer/Docker-Container/Use-Watchtower-to-automatically-update-Docker-images-and-containers/)
- [storjlabs/watchtower Tags | Docker Hub](https://hub.docker.com/r/storjlabs/watchtower/tags)

View File

@@ -0,0 +1,34 @@
{
"nodes":[
{"id":"6c6ff5d0e7850ea8","type":"group","x":920,"y":-360,"width":940,"height":1280,"label":"Docker"},
{"id":"e94c9e71b9aeaa89","type":"group","x":440,"y":-360,"width":400,"height":1100,"label":"基本設定"},
{"id":"acb6cf6a8010bb24","type":"group","x":1940,"y":-360,"width":480,"height":349,"label":"備份設定"},
{"id":"d624199752cf24de","type":"text","text":"![[更新與安裝工具]]","x":460,"y":-340,"width":360,"height":120},
{"id":"6875474760fafe7c","type":"text","text":"![[raspi-config]]","x":460,"y":-200,"width":360,"height":140},
{"id":"6e59f6b9f36b24e2","type":"text","text":"![[安裝]]","x":-40,"y":132,"width":383,"height":177},
{"id":"a63a5baed201beda","type":"text","text":"![[設定日誌大小]]","x":460,"y":163,"width":360,"height":180},
{"id":"b77234a9cdf72aad","type":"text","text":"# 安裝 docker\n[[Docker|Docker]]","x":940,"y":-340,"width":440,"height":120},
{"id":"d0711febf5985ed5","type":"text","text":"# 安裝nginx-certbot\n教學: [iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天](https://ithelp.ithome.com.tw/m/articles/10301801\n\nGithub: [JonasAlfredsson/docker-nginx-certbot: Automatically create and renew website certificates for free using the Let's Encrypt certificate authority.](https://github.com/JonasAlfredsson/docker-nginx-certbot)","x":940,"y":-190,"width":440,"height":240},
{"id":"b900ad17a2841b99","type":"text","text":"# 安裝 Filebrowser\n[官方安裝流程](https://filebrowser.org/installation#docker)","x":1400,"y":-340,"width":440,"height":120},
{"id":"bc030994aafc5a3b","type":"text","text":"![[bashrc]]","x":460,"y":-37,"width":360,"height":177},
{"id":"f210470376a4829d","type":"text","text":"![[設定Cloudflare DDNS]]","x":460,"y":370,"width":360,"height":150},
{"id":"ef9431e16c90f57f","type":"text","text":"設定![[smb client]]","x":460,"y":540,"width":360,"height":180},
{"id":"2a7d5efcc0f2dc0e","type":"text","text":"# 安裝 Portainer\n教學 [Portainer一款圖形化容器管理工具方格子 vocus](https://vocus.cc/article/643e9f74fd89780001b51739)\n\n官網[Portainer: Container Management Software for Kubernetes and Docker](https://www.portainer.io/)","x":940,"y":489,"width":440,"height":191},
{"id":"8cac63e48dff1f2a","type":"text","text":"# 安裝 Gitea\n官方教學[Installation with Docker](https://docs.gitea.com/installation/install-with-docker)\n\n設定Gmail寄信[Gitea 使用 Gmail 寄信 - 筆記ZONE](https://zonego.tw/2021/11/14/gitea-gmail/)\n","x":940,"y":80,"width":440,"height":140},
{"id":"94fa9ef036dbe62a","type":"text","text":"# Speedtest 測試\n超簡單命令`docker run --rm robinmanuelthiel/speedtest:latest`\n\nGithub: [robinmanuelthiel/speedtest: Check internet bandwidth from a Docker container and save the results to an InfluxDB](https://github.com/robinmanuelthiel/speedtest)","x":940,"y":253,"width":440,"height":207},
{"id":"94f3e389e2687b35","type":"text","text":"# 安裝 Watch Tower\n![[Watchtower#或使用 docke-compose.yml|docke-compose.yml]]","x":1400,"y":-190,"width":440,"height":322},
{"id":"fc32cf264646fdec","type":"text","text":"# 安裝 Storj\n![[Storj]]","x":1400,"y":160,"width":440,"height":300},
{"id":"ff16e3814718d144","type":"text","text":"# 設定 crontab\n1. 用[[ddns.sh]]定時更新DNS\n2. 用[[backup_docker_gitea.sh]]備份 gitea docker\n3. 用[[backup_pi.sh]]備份整張SD卡","x":1960,"y":-340,"width":440,"height":150},
{"id":"3f1bf9d99d9d544d","type":"text","text":"# 安裝 [Nxtcloud](https://nextcloud.com/)\n![[Nextcloud]]","x":1400,"y":489,"width":440,"height":191},
{"id":"dac28a6e83be787c","x":940,"y":720,"width":440,"height":180,"type":"text","text":"# 安裝 Grafana\n![[Grafana]]"}
],
"edges":[
{"id":"9683c15c63c167c0","fromNode":"6e59f6b9f36b24e2","fromSide":"right","toNode":"e94c9e71b9aeaa89","toSide":"left"},
{"id":"af36558e6c250c94","fromNode":"d624199752cf24de","fromSide":"bottom","toNode":"6875474760fafe7c","toSide":"top"},
{"id":"feff628bc758f1e4","fromNode":"6875474760fafe7c","fromSide":"bottom","toNode":"bc030994aafc5a3b","toSide":"top"},
{"id":"f1a7af20d2d64873","fromNode":"bc030994aafc5a3b","fromSide":"bottom","toNode":"a63a5baed201beda","toSide":"top"},
{"id":"64bd8b56a86d56af","fromNode":"a63a5baed201beda","fromSide":"bottom","toNode":"f210470376a4829d","toSide":"top"},
{"id":"28432d91108beecd","fromNode":"e94c9e71b9aeaa89","fromSide":"right","toNode":"6c6ff5d0e7850ea8","toSide":"left"},
{"id":"999cc182541e11a4","fromNode":"6c6ff5d0e7850ea8","fromSide":"right","toNode":"acb6cf6a8010bb24","toSide":"left"}
]
}

View File

@@ -0,0 +1,20 @@
```shell
#!/bin/sh
WORK_DIR="/home/awin/docker/gitea"
SAVE_PATH="/media/upload"
NOW_DATETIME="$(date +'%Y%m%d_%H%M%S')"
BACKUP_FILE_PATH="$SAVE_PATH/docker_backup/gitea/backup_docker_gitea_$NOW_DATETIME.tar"
BACKUP_CMD="sudo tar -cvf $BACKUP_FILE_PATH data docker-compose.yml"
echo "$BACKUP_FILE_PATH"
echo "$(date +'%F %R:%S'): Backup start. CMD = $BACKUP_CMD" > /home/awin/log/backup_docker_gitea.log
mkdir -p $SAVE_PATH/docker_backup/gitea
sudo docker compose -f $WORK_DIR/docker-compose.yml down
cd $WORK_DIR
$BACKUP_CMD
sudo docker compose -f $WORK_DIR/docker-compose.yml up -d
echo "$(date +'%F %R:%S'): Backup finished." >> /home/awin/log/backup_docker_gitea.log
```

View File

@@ -0,0 +1,15 @@
```shell
#!/bin/sh
NOW_DATETIME="$(date +'%Y%m%d_%H%M%S')"
SAVE_FOLDER="/media/upload/pi_backup"
SAVE_FILENAME="pi4_$NOW_DATETIME.img"
CMD="sudo /home/awin/bin/image-utils/image-backup -i $SAVE_FOLDER/$SAVE_FILENAME"
LOG_FILE="/home/awin/log/backup_pi4.log"
mkdir -p $SAVE_FOLDER
echo "$(date +'%F %R:%S'): Backup start. CMD = $CMD" > $LOG_FILE
$CMD
echo "$(date +'%F %R:%S'): Backup finished." >> $LOG_FILE
```

View File

@@ -0,0 +1,5 @@
## `~/.bashrc`
```bash
alias ll='ls -al'
alias pwoff='sudo shutdown -h now'
```

View File

@@ -0,0 +1,40 @@
## `/home/awin/script/ddns.sh`
```bash
#!/bin/bash
CF_ACCESS_TOKEN=033xQP4_ZpTq3sSkeftz5J6BWw_R9eoDNTba7zfH
CF_ZONE_ID=1d6a623d1780c31544fc86f718dac16e
URLS=('awin.one'
'blog.awin.one'
'ftp.awin.one'
'git.awin.one',
'storj.awin.one')
CF_RECORD_IDS=('d67b2a1b3d7cd520b8e8dad2cb522460'
'69dcc0bd619b1a3d4a71458faff2aa50'
'bd397d9779d42c0b92c9c9c47b765769'
'4eccb48e85f2daa8fefeb92c8cb4b4ee'
'216d631bc860c6a11b62e3a1003f3e3e')
INTERNET_IP=`curl -s http://ipv4.icanhazip.com`
INTERFACE_IP=`ip address show ppp0 | grep ppp0 | grep global | awk '{print$2}'`
DNS_RECORD_IP=`dig +short "${URLS[0]}" | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | awk 'NR==1{print}'`
NOW_TIME=`date`
if [ "$INTERNET_IP" != "$DNS_RECORD_IP" ]
then
echo "Renew IP: ${DNS_RECORD_IP} to ${INTERNET_IP}"
echo "${NOW_TIME}: Renew IP: ${DNS_RECORD_IP} to ${INTERNET_IP}" > /home/awin/log/ddns.log
for ((i = 0; i < ${#URLS[@]}; i++)); do
curl -X PUT "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/dns_records/${CF_RECORD_IDS[$i]}" \
-H "Authorization: Bearer ${CF_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"'${URLS[$i]}'","content":"'${INTERNET_IP}'","ttl":120,"proxied":false}'
done
else
echo "No change: ${INTERNET_IP}"
echo "${NOW_TIME}: No change: ${INTERNET_IP}" > /home/awin/log/ddns.log
fi
```
### 參考
- [5 分鐘整合 Cloudflare API 實做 Cloudflare DDNS 動態 IP 對應網址](https://blog.toright.com/posts/7333/cloudflare-ddns)
- [自架 DDNS 教學:用 Cloudflare API 達成多域名同步更新! | by Rex | Medium](https://blog.rexyuan.com/%E7%94%A8-cloudflare-dns-api-%E4%BE%86%E9%81%94%E6%88%90-ddns-adaee3c5a84d)

View File

@@ -0,0 +1,3 @@
## `raspi-config`
1. 打開ssh與vnc
2. 開機進入console

View File

@@ -0,0 +1,5 @@
1. 到[官網](https://www.raspberrypi.com/software/)下載`imager`
2. 記得在`imager`裡面設定
1. ssh public key
2. WIFI
3. account/password

View File

@@ -0,0 +1,3 @@
1. `sudo apt update`
2. `sudo apt upgrade -y`
3. `sudo apt install dnsutils`

View File

@@ -0,0 +1,3 @@
用[[crontab]]設定[[ddns.sh]]
1. `crontab -e`
2. 加入 `*/15 * * * * /home/awin/script/ddns.sh`

View File

@@ -0,0 +1,7 @@
打開`/etc/systemd/journald.conf`
- `SystemMaxUse=1G`
- `RuntimeMaxUse=100M`
![[journalctl#重啟日誌]]
journalctl使用說明[[journalctl]]