My recommendation is to put all of the variables in an environment file, and use systemd's EnvironmentFile
(in [Service]
to point to it.
One of my backup service files (I back up to disks and cloud) looks like this:
[Unit]
Description=Backup to MyUsbDrive
Requires=media-MyUsbDrive.mount
After=media-MyUsbDrive.mount
[Service]
EnvironmentFile=/etc/backup/environment
Type=simple
ExecStart=/usr/bin/restic backup --tag=prefailure-2 --files-from ${FILES} --exclude-file ${EXCLUDES} --one-file-system
[Install]
WantedBy=multi-user.timer
FILES
is a file containing files and directories to be backed up, and is defined in the environment file; so is EXCLUDES
, but you could simply point restic at the directory you want to back up instead.
My environment file looks essentially like
RESTIC_REPOSITORY=/mnt/MyUsbDrive/backup
RESTIC_PASSWORD=blahblahblah
KEEP_DAILY=7
KEEP_MONTHLY=3
KEEP_YEARLY=2
EXCLUDES=/etc/backup/excludes
FILES=/etc/backup/files
If you're having trouble, start by looking at how you're passing in the password, and whether it's quoted properly. It's been a couple of years since I had this issue, but at one point I know I had spaces in a passphrase and had quoted the variable, and the quotes were getting passed in verbatim.
My VPS backups are more complex and get their passwords from a keystore, but for my desktop I keep it simple.