# Do KopiaUI backups work while Mac is sleeping?

**URL:** <https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642>\
**Category:** General Topics\
**Created:** [January 10, 2025, 7:47am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642 "2025-01-10T07:47:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 7:47am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/1 "2025-01-10T07:47:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 10, 2025, 9:00am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/2 "2025-01-10T09:00:45Z")

</div>

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](https://ss64.com/mac/pmset.html) to schedule wake up - it supports one repetitive event and multiple single ones.

Use [caffeinate](https://ss64.com/mac/caffeinate.html) to keep macOSt awake when running kopia backup

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 6:26pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/3 "2025-01-10T18:26:17Z")

</div>

Got it, thanks for sharing and for linking those two solutions.

I wonder if it would also be possible to use [Automator](https://support.apple.com/guide/automator/welcome/mac) 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.

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 10, 2025, 6:48pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/4 "2025-01-10T18:48:58Z")

</div>

I run my backup once a day so it is simple setup:

1. set automatic wakeup everyday at midnight:

```auto
   sudo pmset repeat wake MTWRFSU 00:00:00

```

1. then bash script is triggered by launchd at 00:01 and `caffeinate` makes sure that mac does not go sleep before it finishes:

```auto
   #!/bin/bash
   # prevent sleep until this script is finished
   /usr/bin/caffeinate -i -w $$ &
   ...
   kopia snapshot create ...
   kopia maintenance ...
   kopia snapshot verify ...
   exit

```

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 6:51pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/5 "2025-01-10T18:51:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 10, 2025, 6:53pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/6 "2025-01-10T18:53:52Z")

</div>

`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…

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 6:59pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/7 "2025-01-10T18:59:15Z")

</div>

I see, excellent. I assume if I want pmset to wake the mac twice then I would do something like this:

```auto
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?

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 10, 2025, 7:02pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/8 "2025-01-10T19:02:14Z")

</div>

> [@harrison](#):
>
> I assume if I want pmset to wake the mac twice

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:

> <https://apple.stackexchange.com/questions/56635/schedule-multiple-wake-up-times-for-mac>

Effectively what you have to do is to use pmset to schedule next wake up event from within your backup script.

> [@harrison](#):
>
> 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?

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.

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 7:07pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/9 "2025-01-10T19:07:27Z")

</div>

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:

```auto
# 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

```

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 10, 2025, 7:08pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/10 "2025-01-10T19:08:54Z")

</div>

Yeap - I use something very similar.

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 8:19pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/11 "2025-01-10T20:19:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 10, 2025, 8:25pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/12 "2025-01-10T20:25:32Z")

</div>

Check `brtcl` command.

For example to download all items run:

```auto
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.

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 8:37pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/13 "2025-01-10T20:37:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 10:12pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/15 "2025-01-10T22:12:23Z")

</div>

> [@kapitainsky](#):
>
> ```auto
> #!/bin/bash
> # prevent sleep until this script is finished
> /usr/bin/caffeinate -i -w $ &
> ...
> kopia snapshot create ...
> kopia maintenance ...
> kopia snapshot verify ...
> exit
> 
> ```

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](https://kopia.io/docs/reference/command-line/common/snapshot-create/)

edit 2: Also if I only have Kopia UI installed will these commands still function?

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 10, 2025, 10:51pm UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/16 "2025-01-10T22:51:11Z")

</div>

Any reason to add a sleep timer in addition to the wake timer?

```auto
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.

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 11, 2025, 6:22am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/17 "2025-01-11T06:22:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 11, 2025, 6:38am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/18 "2025-01-11T06:38:22Z")

</div>

> [@harrison](#):
>
> In this backup script, can you share an example of what “…” should be replaced with?

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:

```auto
   kopia snapshot create --all
   kopia maintenance run --full
   kopia snapshot verify --verify-files-percent=3

```

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 11, 2025, 6:44am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/19 "2025-01-11T06:44:17Z")

</div>

Ah, I see - ok that makes more sense! Thank you. Ok here is what I have so far

```auto
#!/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)?

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/kapitainsky/32/535_2.png) [@kapitainsky](https://kopia.discourse.group/u/kapitainsky)\
**Post date:** [January 11, 2025, 6:52am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/20 "2025-01-11T06:52:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![harrison](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@harrison](https://kopia.discourse.group/u/harrison)\
**Post date:** [January 11, 2025, 6:54am UTC](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642/21 "2025-01-11T06:54:52Z")

</div>

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.

[Next page](https://kopia.discourse.group/t/do-kopiaui-backups-work-while-mac-is-sleeping/3642.md?page=2)
