I use the open source borg backup tool to make a daily backup of my Documents folder which is also on iCloud drive. I use a LaunchAgent stored in my local library directory to execute a bash script which takes care of the backup. The script also does a backup of another folder which is not on iCloud drive and this works just fine. However, the documents folder is not properly backup up. Just an empty folder is created. If I run the bash script manually, then all works fine. I suspect it is some security measure by Apple that prevents the automatic backup of the folder. Can't help but think of this Apple ad
Does anyone know how to solve this? And no, I don't want to use TimeMachine for a variety of reasons.
PS: Here is my agent file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.tom.snapborg</string>
<key>UserName</key>
<string>tom</string>
<key>Program</key>
<string>/Users/tom/cloud/Dropbox/config/BashScripts/snapborg.sh</string>
<key>StartInterval</key>
<integer>1800</integer>
<key>Debug</key>
<false/>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>
And here is the script
#!/bin/bash
# Check if it is a least 8 in the morning
[ `date +%H` -lt 8 ] && exit
# Check if last backup is at least one day old
lbd=$( cat $HOME/.logs/borg.log )
[ `date -v -1d +%Y%m%d` -lt "$lbd" ] && exit
# Wait a bit for network and check whether server can be reached
sleep 20
ssh -q tom@redacted exit || exit
# Check if upload speed is >= 20MBit (requires speedtest, can be installed with homebrew)
speed=`/usr/local/bin/speedtest --no-download --single --csv | cut -d "," -f 8 | cut -d "." -f 1`
[ "$speed" -lt 20000000 ] && exit
# Unmount BORG repository in case it is mounted
mount | grep $HOME/Library/mount/borg > /dev/null && diskutil unmount $HOME/Library/mount/borg
# Define Repository
REPOSITORY=ssh://tom@redacted:22/home/tom/backup
# Directories to backup
DIR1=$HOME/cloud
DIR2=$HOME/Documents
# Passphrase
export BORG_PASSPHRASE='redacted'
# Backup
osascript -e 'display notification "Backup in progress" with title "BORG STATUS"'
/usr/local/bin/borg create "$REPOSITORY"::'tml-{now:%Y-%m-%d}' "$DIR1" "$DIR2"
# Delete old backups
/usr/local/bin/borg prune "$REPOSITORY" --prefix 'tml-' --keep-daily=7 --keep-weekly=8 --keep-monthly=24
osascript -e 'display notification "Backup complete" with title "BORG STATUS"'
# Write backup date into log
date +%Y%m%d > $HOME/.logs/borg.log