I believe KopiaUI should be able to do this, looks like in the past there were some bugs and it was not working properly.
Does anyone know if it is now working properly?
I believe KopiaUI should be able to do this, looks like in the past there were some bugs and it was not working properly.
Does anyone know if it is now working properly?
kopiaUI neither supports waking up macOS nor prevents it from going sleep when running.
You have to use cmd and DYI wrapper script(s) yourself to support it.
Use pmset to schedule wake up - it supports one repetitive event and multiple single ones.
Use caffeinate to keep macOSt awake when running kopia backup
Got it, thanks for sharing and for linking those two solutions.
I wonder if it would also be possible to use Automator on Mac to do this?
Is there a simple syntax to run all Kopia Snapshots that I could use in Automator? I believe Automator can wake up the mac and perform it’s actions while the Mac is asleep.
Or perhaps combining pmset, caffeinate, and Automator would be the best/easiest way to do it.
I run my backup once a day so it is simple setup:
sudo pmset repeat wake MTWRFSU 00:00:00
caffeinate
makes sure that mac does not go sleep before it finishes: #!/bin/bash
# prevent sleep until this script is finished
/usr/bin/caffeinate -i -w $$ &
...
kopia snapshot create ...
kopia maintenance ...
kopia snapshot verify ...
exit
Got it, I might try to take that code and run it in Automator, then I will have easy access to change it in the future if needed.
How do you do it though - are you entering that in the terminal and then it is set to run daily until you change it?
pmset
you run it only once. It sets wakup schedule which is valid forever (or until you change it). You can find plenty of examples on Google how to customise it.
backup
script - you can trigger it by whatever means you like - launchd, automator, crontab…
I see, excellent. I assume if I want pmset to wake the mac twice then I would do something like this:
sudo pmset repeat wake MTWRFSU 04:30:00 wake MTWRFSU 16:30:00
And if my Mac is not connected to the internet for whatever reason and I run the backup script - will that cause issues, preventing the mac from returning to sleep as it is trying to complete the snapshot?
I am afraid your assumption is wrong:) You can only have one repeating schedule.
If you need more wake up events per day it is getting a bit more complicated. See for example:
Effectively what you have to do is to use pmset to schedule next wake up event from within your backup script.
It is not ideal but should not create disaster. You can also simply add to your script connectivity check at the beginning and in case no internet do not run kopia.
Ah, I see. Ok well I think once per day is enough but I will look into that in the future.
As far as adding that connectivity check. Do you know of a simple way to do that? After some quick googling I found this:
# Function to check for internet connection
check_internet() {
if ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
echo "Internet is available."
return 0
else
echo "No internet connection. Skipping Kopia operations."
return 1
fi
}
# Check for internet connection
if ! check_internet; then
exit 0 # Exit script if no internet connection
fi
Yeap - I use something very similar.
Thank you so much for your help!
Another question, and this might be fairly specific. But I am hoping to find a way to force iCloud to sync a specific folder on my iCloud drive before having Kopia do that snapshot. Do you know of a way to do that?
Check brtcl
command.
For example to download all items run:
cd ~/Library/Mobile\ Documents/com~apple~CloudDocs/ && find . -type f -print0 | xargs -0 brctl download
You can customise it to run over specific iCloud directory only.
In the latest macOS you can also enable specific items pinning
making sure that they are always downloaded and never evicted - but I have not tried it yet.
Ok I will take a look at that. And yes I am using the “Keep Downloaded” feature on macOS Sequoia to keep my iCloud folder that I am backing up with Kopia downloaded. It seems to work well, but I want to ensure any updates I make to the files on my iPhone are pulled in before Kopua does it’s snapshot.
In this backup script, can you share an example of what “…” should be replaced with?
The first occurrence of “…” on the 4th line in particular I am confused about.
I assume the other occurrences of “…” should be replaced with a file path or a Kopia reference number?
edit: and does there need to be a “$” in front of each Kopia command as shown HERE
edit 2: Also if I only have Kopia UI installed will these commands still function?
Any reason to add a sleep timer in addition to the wake timer?
sudo pmset repeat wake MTWRFSU 00:00:00
sudo pmset repeat sleep MTWRFSU 00:30:00
Like that?
edit: after some testing it looks like the Mac just goes back to sleep after a short period of time so this doesn’t seem necessary.
It is up to you how you want to manage it. Adding sleep timer requires making sure that kopia run is finished. One day it can be finished by 0005 but another by 0035.
IMO it is better to run manually pmset sleepnow
at the end of backup script.
Replace it with other commands/options you need. You already mentioned two things you want to add - checking network state and downloading some iCloud data.
I only included key elements to show how sleep is prevented.
In case of kopia part it can be something like:
kopia snapshot create --all
kopia maintenance run --full
kopia snapshot verify --verify-files-percent=3
Ah, I see - ok that makes more sense! Thank you. Ok here is what I have so far
#!/bin/bash
# prevent sleep until this script is finished
/usr/bin/caffeinate -i -w $$ &
# Function to check for internet connection
check_internet() {
if ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
echo "Internet is available."
return 0
else
echo "No internet connection. Skipping Kopia operations."
return 1
fi
}
# Check for internet connection
if ! check_internet; then
exit 0 # Exit script if no internet connection
fi
# Sync Obsidian Vaults iCloud folder
cd ~/Library/"Insert rest of file path" && find . -type f -print0 | xargs -0 brctl download
# Kopia Snapshots
kopia snapshot create --all
kopia maintenance --full
kopia snapshot verify --verify-files-percent=3
# Put mac to sleep now that snapshot is completed and verified
pmset sleepnow
exit
I’m pretty new to Bash / Shell, Python is more my speed. Does that look good at a glance as far as organization (no internet will end the script, iCloud will download before Snapshot)?
Yeap, Look OK. If you prefer Python then you could do all in this language instead.
For shell scripts I suggest always to run your code through shellcheck
(you can install it via brew). It is also good learning exercise (regardless of your skills) as it has very comprehensive explanations.
Thanks for taking a Quick Look. Ok maybe I will switch it all to Python but I do want to learn more Bash / Shell so this has been a good exercise.
Ok I will check that out, that would be great for me.