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">

And here is the script

# 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
# Directories to backup
# 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
  • I did, but I don't think this is where the problem lies, as everything works perfectly fine if I don't use the Documents folder as the folder to backup – 220284 Sep 6 '20 at 11:11
  • Please edit your question and add the contents of the snapborg.sh file. – user3439894 Sep 6 '20 at 11:16
  • I did, again, I don't think this is where the problem lies, but it may be helpful for others. – 220284 Sep 6 '20 at 11:24
  • What version of macOS are you running? If Debug is set to true in the plist file what does it show in system.log? Why do you have AbandonProcessGroup set to true in the plist file? – user3439894 Sep 6 '20 at 11:35
  • So, to clarify: the script runs as expected if launched manually, and the script works when called by launchd if ~/Documents is not the source? – benwiggy Sep 6 '20 at 11:38

You must log in to answer this question.

Browse other questions tagged .