Back up folder on iCloud to a Mac

I asked this questions in 2021, and I am still not making this happen. I want to back up a folder that is on iCloud to my Mac everyday. This should not be brain science. I made a forever novice macro in the next reply.

I half made a macro.
It is probably not what you would do, but I am a hopeless novice. So, please bear with me. I am stuck on these points.

  1. How do I turn it on everyday? It has to be automated because I will for get to do it.
  2. How do I make a new folder labeled with todays date?

The files in the the clip board so I would finish the macro be pasting the files in the new folder. I am thinking I only need to do copy paste.

I hope I am making sense.

Backup Obsidian to Doc folder on Mac.kmmacros (5.5 KB)

Look into the cron trigger.

See Dates and Times, which explains how to use a date/time token.

I see you already have an empty new folder action in your macro and I think you are a lot more able with KM than you give yourself credit for, so I won't give an example of how to do this now, but of course do let us all know if you get stuck!

Tips:

  • You can append the date/time token to other text, so that you can create, say, "~/Documents/My example folder 2023-06-14" rather than just "~/Documents/2023-06-14".
  • For added flexibility (and complexity :slight_smile: ), you could have an action to set a variable (e.g. %icloud_stuff%) with that sort of composite name, have other actions change it further as needed, and then create the folder %Variable%icloud_stuff%
  • I recommend that year-month-day format (ISO 8601), not least because it means that alphabetical file listings are also chronological, but note that you do not have to include dashes as I have done.

The action Set variable to clipboard is the missing link.

Thank you @Kevinb for your suggestion to make a more generalized macro. That sounds too advanced, so I am going to stick to just getting a specific folder of documents on iCloud saved to a folder on my Mac.

Backup Obsidian to Doc folder on Mac.kmmacros (5.5 KB)

I got a new folder with the name */15 * * * *% to be made. But then I changed something in my macro and the new folder is not made. (what I want is today's date including the time.) I see time of the day indications but how I use that is not clear.

I am theoretically aiming at getting the folder on iCloud to be copied in the above folder. This should happen every 15 minutes.

At the top of the macro, I added commands to save the documents in the application every 15 minutes if the application is running. I really want the change to be made when the application is changed, but that is not available.
I want the trigger to be the application is being used (changed), Then wait 15 minutes to automatically save the documents. I do not see that possibility among the possibilities to trigger the macro, aside from writing a script which I am not able to do.

Starting with the obvious -- why? What will this macroed backup get you that a Time Machine backup doesn't? If you aren't using TM, can't your preferred backup solution do this, and with a lot less effort on your part?

This is very different to your original "every day", and requires a different approach -- once every day you can copy the entire Obsidian folder as @kevinb suggests, but a complete copy every 15 minutes is a waste of drive space and you should look at syncing Obsidian to a "daily" folder instead.

There's no reliable way to know if an application is being used, although you can use "activated" as a proxy. If you are really after updates every 15 minutes to a "daily" backup it's probably better to ignore your use of Obsidian and simply let the sync take care of whether or not files have changed and the backup needs updating.

So have a think about what you are trying to achieve. If it still looks like KM is the best tool for the job then fully describe what you want to happen -- it shouldn't be too difficult to create a macro to do it.

I can't find the post you're referring to on this forum so I'm assuming you asked somewhere else. If so, what answer did you get then?

To be clear: I didn't suggest that; I answered questions about aspects of your existing macro. :wink:

Perhaps the "tips" I added made it all seem more complicated than it is. Start with that Dates and Times page that I linked to, if you haven't already.

The date/time tokens offer a lot of choices and that can be confusing initially. But as examples:

  • Here is a token that represents the current local time: %ICUDateTime%hhːmm%
  • Here is the current local date, formatted as year-month-day: %ICUDateTime%yyy-MM-dd%
  • Combining those examples, here is the current date and time: %ICUDateTime%yyy-MM-dd-hhːmm%.

Try those out in a simple test macro and you should get the idea.

I tend not to ask why, since everyone has their own use cases and opinions, and so discussions can become more complicated than I want to deal with, but we are all fortunate that @Nige_S and other KM adepts here are willing to open such cans of worms! Yes, it's an excellent question.

I do also wonder whether the safest and easiest option might not be Obsidian Sync at $8 per month.

I was trying to remember the words for the backup that you can buy for Obsidian. Now that I see how difficult back up of iCloud is with KM, I am going to get the Opsidian backup. Thank you.

Thank you @Kevinb I am going to try out devonthink backups done on iCloud. It is the same, but I am not so nervous about devonthink. I do not use it much with multiple computers. Nor do I make changes as often as I do with Obsidian. As @Nige_S suggested, buying Obsidian's automatic backup makes more sense for me, a permanent novice with KM.

Thank you @tiffle I am not getting anything done, but I am getting answers from others. I think you need to be komputer saavy to use KM.

Don't be discouraged. Some tasks are just more complicated than others.

I back up various files frequently (like every time I make a change) during the day and I use the Mirror Mirror Macro to do that. It's simple to use (and use over and over) but it's very smart.

It's not difficult, but you do need a plan. Making a plan means knowing what you want to do, and deciding what you want to means knowing why you want to do it.

If you just want regular backups of your Obsidian directory, Time Machine (or your backup software of choice is already doing that). If you aren't backing up your Mac then fixing that should be your first priority!

If you want full version control with one year retention (plus the option to work on other platforms and collaborate in a team), @kevinb's suggestion of Obsidian Sync is a good one. This is still not a backup, so if you haven't sorted out Time Machine (or something else) after reading the previous paragraph you still need to do that.

If you are happy with a daily copy of your Obsidian vaults to another folder/external drive/Dropbox-or-similar, that's really easy to do in KM -- indeed, the biggest problem might be how to reliably automatically trigger the macro since triggers won't fire if your Mac is asleep. But if you're always working at 5pm you could use a daily periodic set to 4:55pm, or if you always log out at the end of the day you could use tomorrow's login to trigger the copy of today's files.

If you want more frequent copies you could run the KM macro every 15 minutes -- what you do in the macro will depend on whether you want a fresh copy of the entire Obsidian folder each time, an updated copy of all files, or you if want to retain versions of files changed that day (at which point Obsidian Sync is a much better choice).

Not particularly -- but you do need to be able to define your problem then break it down into smaller, solvable, parts that you can "translate" into KM-speak and then build back up into a macro.

So let's do that...

"I want to make a copy of my iCloud Obsidian files" -- the iCloud bit is important because that tells us where the files are on your computer: the Library/Mobile Documents/iCloud~md~obsidian/Documents folder. But there's still a lot of detail missing.

"At 5pm every day I want to make a new folder containing the contents of my Obsidian iCloud directory." Better. But where should this new folder be made, and how should it be named?

"At 5pm every day I want to make a new folder, named with today's date in 2023-06-13 format, into a folder called "Obsidian Backups" in my Dropbox folder and then copy the contents of my Obsidian iCloud directory to it." Now you've something to work with!

Make a new macro in the KM Editor. Ignore the trigger for now -- that can wait until the macro does what you want when triggered manually. Start with the verbs -- they're your KM Actions -- and either search the Action list in the Editor or look on the wiki page for something that matches.

(We aren't using them here, but "If this then that", loops, and similar are verbs -- and therefore KM Actions -- as well. Think of them as "making a decision about" or "doing a thing until", etc.)

Our "doings" are "make a new folder" and "copy contents". The "New Folder" action is easily found, so drop that in first. "Copy contents" gets nothing but "copy" gets us some options, the closest of which looks like "Copy a File" -- and if you look on the wiki you'll see that a "compound" action with lots of options, one of which is "Copy -- copies a file or folder". So drop that in too.

Now look for "noun"-type things -- that's the data you either put in the macro, like the path to a folder, or that KM can get itself using other actions, tokens, functions, or calculations. We've got:

  1. The path to our Dropbox folder we want to store the backups in
  2. The name of our new folder -- today's date in a certain format
  3. The path to the Obsidian data folder

Since this is a macro for us we don't need to get too fancy and create variables and prompts and whatever. We know where these folders are and can hard-code them into the macro using the "file picker" beside each field to get the path:

...although we aren't there yet, we still need to add the date as the name of the new folder. You can do that in a number of ways, but if you look at the available tokens for something date-related you'll find "ICUDateTime", which "returns the current date and time in the specified format". Perfect!

There's plenty of examples, plus links to documentation, on that page and those (or a quick search on the Forum) will quickly get you to %ICUDateTime%yyyy-MM-dd% as the way to get the current date in the format we want. This is a text token and can be used in any KM text field, and the "result" will replace the token. We need to add an extra / to the paths before putting in the token, so:

Test it manually by clicking the "Run" button, and if everything works you're basically finished! You just need to add your trigger, and "Time of Day" looks most suitable -- we said 5pm, but let's make that Mon-Fri only:

And a no-frills, daily copy of all your Obsidian vaults to Dropbox is done:

Daily Copy Obsidian Vaults to Dropbox.kmmacros (2.2 KB)

Image

That all seems very long-winded -- but I promise you, it takes a lot longer to explain than to do! And once you've got the pattern of "Plan - Break down - Solve - Build up" ingrained, the rest is just searching the Wiki and a bit of practice.

Our macro still isn't perfect -- for example, we're copying a folder called "Documents" that contains our vaults. But once you've a basic macro working you can can on to tweak it however you want. In this case we might want to loop through the contents of "Documents", copying the individual items instead, and that's a pretty simple change:

Daily Copy Obsidian Vaults to Dropbox v2.kmmacros (2.9 KB)

Image

As always, none of the above is gospel! Everyone will have their own way of doing things, and many people on the Forum will write a much better macro than I've done here. You'll soon find your own methods, and will decide your own level of "good enough to use" :wink:

I'm a huge fan of KM and use it for the 30+ macros I've built about a thousand times a day. But it's not perfect for everything and in this case you might find the app that I use for backing up folders, SyncTime, to be ideal for you.

Their site doesn't mention iCloud specifically but I've got a bunch of different folder backups to/from external drives so I presume if put the iCloud Drive icon on your desktop it would work. It's worth a try and for $8 it could save you a whole lot of time.

Thank you @Scott721. I downloaded Synctime. I get myself in trouble trying to do things that are too complicated. I am trying to use KM more, but I have to think of simpler uses.

This is how we learn. Let me know if you need any assistance with that app, or with other simple uses of KM. Good luck!

I am going to try out devonthink backups done on iCloud.

I am not sure what you mean here but…

  • You should never put a DEVONthink database in any cloud-synced location or you could irreparably damage it.
  • Sync is not a backup – neither advocated or advertised as such. Proper primary backups with local drives and an app like Time Machine or Carbon Copy Cloner are strongly suggested. Secondary backups to the cloud with a snapshot-style application, e.g., Arq, is also a good idea. Redundancy in backups are advocated if your data is important to you.