I am about to write service that rsync --delete directory /mnt/foo to remote server. However because of --delete option, I'd like to not run it unless /mnt/foo is mounted, as this might result in deletion of all files on remote.
What to achieve it with ConditionX (e.g. ConditionPathIsDirectory) and RequiresMountsFor= directives, and what is the difference (pros and cons of each) ?
Draft: Here is my current sketch:
RequiresMountsFor=/mnt/foo
vs
# assuming there is `bar_only_on_foo` subdirectory on monted directory, which does not exis on unmounted one.
ConditionPathIsDirectory=/mnt/foo/bar_only_on_foo
To add to .service file:
# /etc/systemd/system/rsync_to_remotey.service
# or : /home/$USER/.config/systemd/user/rsync_to_remotey.service
[Unit]
Description=rsync USER X data to REMOTE Y
[Service]
Type=simple
ExecStart=/home/USERX/rsync_userx_to_remotey.sh
For correctness, here is .timer file:
# /etc/systemd/system/rsync_to_remotey.timer
# or : /home/$USER/.config/systemd/user/rsync_to_remotey.timer
[Unit]
Description=Runs every 30 minutes rsync USER X data to REMOTE Y
[Timer]
OnBootSec=30min
AccuracySec=1h
OnCalendar=*:0/30
Unit=rsync_to_remotey.service
[Install]
WantedBy=multi-user.target