一部のプログラムを起動し(一部の出力を表示)、フィードバックを提供echo
するために使用されるシステムタイマーを介してシェルスクリプトを実行します。
root@srv ~ [127]# cat /etc/systemd/system/borg.timer
[Unit]
Description=runs borg every hour
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=multi-user.target
root@srv ~# cat /etc/systemd/system/borg.service
[Unit]
Description=borg backup
[Service]
Type=simple
ExecStart=/etc/local/borg.sh
root@srv ~# cat /etc/local/borg.sh
#!/bin/bash
echo "→→→ starting borg backup at $(date)"
# it is OK to move repositories
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
(...)
スクリプトを対話的に実行すると、
echo
2つの出力(プログラムと出力)が表示されますjournalctl
。タイマーで実行すると、プログラム出力のみが表示されます。
後者が非対話式で実行されることを知っていますが、プログラム出力に誰かが入ってくるので、journalctl
タイマーはどうですか?
このようなフィードバック出力をスクリプトに表示する方法はありますか?
systemctl
以下は、journalctl
スクリプトを渡して一時的に起動したときの出力を比較したものですsytemctl start borg
。これで、「ステージ2」スクリプト(ステージの背後で独自にbash
実行されます)がフィルタリングされた出力の理由になる可能性があるかどうか疑問に思います(単なる推測にすぎません)。borg.sh
python
出力systemctl
:
root@srv ~# systemctl status borg
● borg.service - borg backup
Loaded: loaded (/etc/systemd/system/borg.service; static)
Active: active (running) since Mon 2022-08-08 18:31:54 CEST; 1min 22s ago
TriggeredBy: ● borg.timer
Main PID: 2651152 (borg.sh)
Tasks: 2 (limit: 28688)
Memory: 1.1G
CPU: 54.304s
CGroup: /system.slice/borg.service
├─2651152 /bin/bash /etc/local/borg.sh
└─2651737 /usr/bin/python /usr/bin/borg compact /backup/borg/srv
Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: weekly #4): 231d5f07-3453-46a5-a466-b8760196e120 Sun, 2022-07-03 23:00:11 [ab22320beda4d0f4ac247686ad>
Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: monthly #1): 3b280578-586f-4f62-80c1-b296aa8982c2 Thu, 2022-06-30 23:00:10 [067e23be4b7e33ec7b87f32603>
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:32:48 srv borg.sh[2651687]: Original size Compressed size Deduplicated size
Aug 08 18:32:48 srv borg.sh[2651687]: Deleted data: -3.54 GB -1.61 GB -1.33 MB
Aug 08 18:32:48 srv borg.sh[2651687]: All archives: 2.23 TB 1.82 TB 104.85 GB
Aug 08 18:32:48 srv borg.sh[2651687]: Unique chunks Total chunks
Aug 08 18:32:48 srv borg.sh[2651687]: Chunk index: 199025 7333955
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:32:48 srv borg.sh[2651152]: →→→ compact backup for /backup/borg/srv
Aug 08 18:33:28 srv borg.sh[2651152]: repo: /backup/borg/srv id: 2022-08-08T18:32:00+02:00 hash:
Aug 08 18:33:30 srv borg.sh[2651152]: →→→ ended backup on srv
Aug 08 18:33:30 srv borg.sh[2651152]: →→→ starting backup on outscale
Aug 08 18:33:30 srv borg.sh[2651152]: →→→ create backup for [email protected]:/backup/srv
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/hacs.repositories
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/auth
同じログ行が通過します。journalctl
Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: weekly #4): 231d5f07-3453-46a5-a466-b8760196e120 Sun, 2022-07-03 23:00:11 [ab22320beda4d0f4ac247686adb39bd64533d93c9b02172e4299bf5f7e8ceee8]
Aug 08 18:32:46 srv borg.sh[2651687]: Keeping archive (rule: monthly #1): 3b280578-586f-4f62-80c1-b296aa8982c2 Thu, 2022-06-30 23:00:10 [067e23be4b7e33ec7b87f32603d5a05aa5e1f77e6dff17451b3d63db9130cafc]
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:32:48 srv borg.sh[2651687]: Original size Compressed size Deduplicated size
Aug 08 18:32:48 srv borg.sh[2651687]: Deleted data: -3.54 GB -1.61 GB -1.33 MB
Aug 08 18:32:48 srv borg.sh[2651687]: All archives: 2.23 TB 1.82 TB 104.85 GB
Aug 08 18:32:48 srv borg.sh[2651687]: Unique chunks Total chunks
Aug 08 18:32:48 srv borg.sh[2651687]: Chunk index: 199025 7333955
Aug 08 18:32:48 srv borg.sh[2651687]: ------------------------------------------------------------------------------
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/hacs.repositories
Aug 08 18:33:32 srv borg.sh[2652145]: M /etc/docker/domotique/data/hass/.storage/auth
→→→
で始まるすべてのもの(そして接頭辞を忘れた行)はrepo
から来ますecho
。
答え1
線を表示する方法を見つけましたが、違いを完全に理解していませんでした。
root@srv ~ [SIGINT]# journalctl -u borg -f
Aug 08 18:34:59 srv borg.sh[2652992]: All archives: 1.10 TB 806.57 GB 23.34 GB
Aug 08 18:34:59 srv borg.sh[2652992]: Unique chunks Total chunks
Aug 08 18:34:59 srv borg.sh[2652992]: Chunk index: 104061 5351569
Aug 08 18:34:59 srv borg.sh[2652992]: ------------------------------------------------------------------------------
Aug 08 18:34:59 srv borg.sh[2651152]: →→→ compact backup for [email protected]:/backup/srv
Aug 08 18:35:01 srv borg.sh[2651152]: repo: [email protected]:/backup/srv id: 2022-08-08T18:33:30+02:00 hash:
Aug 08 18:35:03 srv borg.sh[2651152]: →→→ ended backup on outscale
Aug 08 18:35:04 srv borg.sh[2651152]: →→→ ended borg backup at Mon Aug 8 18:35:04 CEST 2022
前に使った
root@srv ~ [SIGINT]# journalctl _COMM=borg -f
Aug 08 18:34:58 srv borg.sh[2652992]: Keeping archive (rule: daily #3): 16cccd33-5293-4a5f-8d36-35a46bfbe3b4 Wed, 2022-08-03 23:00:47 [5ae28fbaef906725950b9b672935c5c1ff9ebc8987c1fb8d96b3db65bbd6e375]
Aug 08 18:34:58 srv borg.sh[2652992]: Keeping archive (rule: daily #4): 226cc3ae-255e-4e24-977b-db1fa32fa741 Tue, 2022-08-02 23:00:55 [271d41a84227ffa104d18073e83760e190b3ec8a255852f7f23e404b50ead583]
Aug 08 18:34:58 srv borg.sh[2652992]: Keeping archive (rule: daily[oldest] #5): 2f43aa48-f6b4-4f69-b4da-d32a3ae3bcf7 Tue, 2022-08-02 16:01:05 [e8c9e47e7dac4f502c1259fbdb19a5783b6b081203dff7d4809ef763467d4c96]
Aug 08 18:34:59 srv borg.sh[2652992]: ------------------------------------------------------------------------------
Aug 08 18:34:59 srv borg.sh[2652992]: Original size Compressed size Deduplicated size
Aug 08 18:34:59 srv borg.sh[2652992]: Deleted data: 0 B 0 B 0 B
Aug 08 18:34:59 srv borg.sh[2652992]: All archives: 1.10 TB 806.57 GB 23.34 GB
Aug 08 18:34:59 srv borg.sh[2652992]: Unique chunks Total chunks
Aug 08 18:34:59 srv borg.sh[2652992]: Chunk index: 104061 5351569
Aug 08 18:34:59 srv borg.sh[2652992]: ------------------------------------------------------------------------------