systemd는 스크립트에 필요한 환경 변수를 읽지 않습니다.

systemd는 스크립트에 필요한 환경 변수를 읽지 않습니다.

백업에 borg백업과 타이머를 사용하고 싶습니다 . systemd나는 borg를 사용하여 몇 가지 수정을 거쳐 내 웹사이트의 스크립트를 백업하고 있습니다. 원본 사진을 보실 수 있어요여기내 스크립트는 다음과 같습니다.

#!/bin/sh

# Setting this, so the repo does not need to be given on the commandline:
export [email protected]:/path/to/repo

# See the section "Passphrase notes" for more infos.
export BORG_PASSPHRASE=SecretPassphrase

# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM

info "Starting backup"

# Backup the most important directories into an archive named after
# the machine this script is currently running on:

borg create                            \
    --remote-path=/usr/local/bin/borg  \
    --verbose                          \
    --filter AME                       \
    --list                             \
    --stats                            \
    --show-rc                          \
    --compression lz4                  \
    --exclude-caches                   \
                                       \
    ::'{hostname}-{now}'               \
    ~/.ssh                             \
    ~/db/dump_*                        \

backup_exit=$?

info "Pruning repository"

# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-' prefix is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:

borg prune                             \
    --remote-path=/usr/local/bin/borg  \
    --list                             \
    --prefix '{hostname}-'             \
    --show-rc                          \
    --keep-daily    7                  \
    --keep-weekly   4                  \
    --keep-monthly  6                  \

prune_exit=$?

# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))

if [ ${global_exit} -eq 0 ]; then
    info "Backup and Prune finished successfully"
elif [ ${global_exit} -eq 1 ]; then
    info "Backup and/or Prune finished with warnings"
else
    info "Backup and/or Prune finished with errors"
fi

exit ${global_exit}

ATM 타이머 없이 서비스를 설정하고 싶습니다.

다음 내용 n.service으로 (작업 이름)을 만들었습니다 ./etc/systemd/system

[Unit]
Description=Example Service

[Service]
Type=simple
User=callmebob
Group=callmebob
Environment="[email protected]:/path/to/repo"
Environment="BORG_PASSPHRASE=SecretPassphrase"
ExecStart=/bin/sh /home/callmebob/backup.sh

[Install]
WantedBy=multi-user.targetshell

이제 콘솔에서:

sudo systemctl daemon-reload
sudo systemctl start n
sudo systemctl status n

서비스가 제대로 실행되는 것 같지만 환경 변수를 읽지 않습니다.

May 18 05:45:31 mydomain systemd[1]: Started Example Service.
May 18 05:45:31 mydomain sh[213874]: Wed 18 May 05:45:31 UTC 2022 Starting backup
May 18 05:45:38 mydomain sh[213903]: passphrase supplied in BORG_PASSPHRASE, by BORG_PASSCOMMAND or via BORG_PASSPHRASE_FD is incorrect.
May 18 05:45:38 mydomain sh[213903]: terminating with error status, rc 2

따옴표 등 없이 거기에 키/값 쌍을 넣어서 사용해 보았 EnvironmentFile으나 그것도 작동하지 않았습니다. 사용해 PassEnvironment도 아무런 효과가 없습니다. 나는 또한 성공하지 못한 채 다양한 서비스 유형을 시도했습니다.

내가 여기서 무엇을 놓치고 있는지 아시나요?

관련 정보