automator application using rsync suddenly deleted many of my files and applications

Hi, I put together a very simple automator routine that syncs a shared folder on another machine with a folder located in iCloud. I run it occasionally so that I can have access to copies of the latest files in that folder from my phone, computers at home etc.

the workflow is as follows:


get specified finder items (path to folder on other computer)

set value of variable (source_folder)

-

get specified finder items (path to folder on iCloud)

set value of variable (target_folder)

-

get value of variable (source_folder)

get value of variable (target_folder)

run shell script

shell:/bin/bash

rsync -avE --delete "$1/" "$2/"


it was working fine for years, then one day a few months back when I ran the app a window popped up asking for my permission to access 'something' (can't remember exactly what, maybe documents folder?) and I just clicked allow, then another asking for another permission for something (wish I knew exactly what) then suddenly various applications shot off of the dock (making the whoosh deleted sound) and files started disappearing from my desktop. there was the spinning gear icon on the menubar, which I clicked and it said 'running script 14% complete' or something along those lines. I clicked the cancel button and everything stopped. In the aftermath iCloud login windows were popping up and finally I restarted the computer to see what would happen. It booted up as though it was a new account being created (asking for preferences for screen, Siri, etc) and had me log in to my apple account. once in, files on the desktop were still there but most applications, photo albums, videos were all reset to default (ie empty photos library and nothing else in the pictures folder). Thankfully I was able to restore with a Time Machine backup.


Anyone have any idea what happened exactly? I would like to continue to use this application but am reluctant. my only alternative is to manually copy/overwrite the folder each time which get to be a slow process when the folder gets filled with files.


Thanks,


G


Mac mini, macOS 12.6

Posted on Jan 4, 2023 9:10 AM

Reply

Similar questions

6 replies

Jan 4, 2023 3:11 PM in response to Geoff Miller

I would start by seeing what variables are being passed to rsync with echo:

Comment out the last line and add echo to print what's being passed to a file on the desktop:

#rsync -avE --delete "$1/" "$2/"
echo Var1: "$1/"  Var2: "$2/" > $HOME/Desktop/File1.txt


(I never liked how Automator handled variables (I have used them as you have), and find that Shortcuts handles variables in a a more understandable way)





Jan 4, 2023 1:15 PM in response to Geoff Miller

Geoff Miller wrote:

Thankfully I was able to restore with a Time Machine backup.

😄

Anyone have any idea what happened exactly?

It went haywire and started deleting your home directory. You should double-check your iCloud settings and the files you have in iCloud to make sure you still have everything. That's the downside to cloud storage. When some script runs amuck like this, it can delete files from every device and in the cloud.

my only alternative is to manually copy/overwrite the folder each time which get to be a slow process when the folder gets filled with files.

Maybe take a step back and revisit what you are trying to accomplish at a high level.


People often get halfway deep into some kind of rabbit hole and post a question here asking for some specific information about how to get to that 7th circle of rabbithell. When we try to ask about the bigger picture, they usually get very upset. This scenario is exactly the kind of thing we are trying to prevent in those cases. You got your rabbit hole working, until the day it trashed your home directory and possibly all your iCloud data.


If you describe what you are trying to do, we can give you better, and safer, ways to accomplish it.

Jan 4, 2023 2:01 PM in response to etresoft

Ok, its seems pretty simple.

There are two users who are both viewing/editing/adding documents to a folder on user 1's iMac.

Both users want to be able to access the latest versions of everything in the folder while in the office (where the two computers are networked together, and also on their iPhones or other computers at home when they are away from the office.


The solution that we started with was user1 would manually copy the latest version of the folder onto their iCloud Drive periodically so that they had up to date items when at home or on the road.

User2 would manually copy the latest version though the network onto their iCloud Drive as well.

The folders are yearly (ie empty jan 1 and items added over the months) so towards the end of the year it was taking a lot of time to copy the folder (writing over existing docs to latest versions). many of the docs remained unchanged, so to speed things up I created the script above using rsync to quickly update the folder. Everything was working great for the last 3 years until the problem happened as described previously to user 2 (happened sometime in october). user 1 (yesterday) ran the script after updating the paths to the new folders created for this year and suddenly the same result happened (ie things disappeared and deleted), only this time it was on user1's computer, which contains the folder that everything is copied from, and also deleted various applications (such as quicken) and all the documents/files/directories in their documents folder, and also Im guessing many preference files etc.


Any ideas?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

automator application using rsync suddenly deleted many of my files and applications

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.