![]() |
rsync /Volumes question
I have a script that automatically backs up certain folders whenever my external HD is attached. mostly it works fine, but occasionally (if I muck something up, like removing the drive too soon or launch the script when the drive isn't attached) rsync creates an actual folder in /Volumes and starts filling it up as though it were the external HD, with hilarious results. apparently rsync can't tell the difference between a separate volume and a folder in /Volumes. so I started poking around to see if I could make a check for myself, and oddly, I can't figure it out myself. how do you distinguish betwen a regular folder in ?volumes and an attached disk? the root drive shows up as a symbolic link, but attached drives seem to be represented as normal folders.
anyone have insights on this? |
Quote:
Since your script (or rsync) seems to be the one creating the folder, just prevent that behavior by checking for the target's presence *first*. If it's not there, don't let rsync proceed: target=/Volumes/some\ disk\ name : : [[ -d $target ]] || exit 1 # no target, no run So that should solve the issue (by prevention). I will note that listing /Volumes with the inode numbers option -i has always shown real volumes with an inode number of "2"... but some other strange (yet very low numbered) values have recently come to my attention. [some 'Directory Services' mount was "7"?] Anyway, simply testing the target path at the right time should do it. -HI- |
Check the inode number of the folder. A mount point will have inode number '2', a regular folder won't.
You could also parse the output of 'mount', 'df', or 'disktool -l' if you prefer. |
Quote:
but know of no "official" documentation. Do you know of such? |
Quote:
|
Quote:
Code:
#!/bin/bash |
Quote:
|
Quote:
@HI and ataraxia: the inode man page says this: Quote:
|
Quote:
But wouldn't it be better to avoid running rsync if the external is not attached? |
Quote:
|
But if before you call rsync, you check to see if the path exists, and if it exists you check to see if it's a folder or a drive, you can decide whether or not to call rsync! It's not the perfect world, but it will let you get started on that portal. ;)
|
Quote:
|
I'm assuming you'd use the same logic in launchd as you were in testing whether or not to run rsync. In that case, launchd might also see a folder as if it were a drive, so you'd be stuck with the same results.
|
Quote:
Quote:
Here's a link to that other thread/post, where the "inode = 7" appeared: Unexpected directory in /Volumes Turns out it was some remote NFS URL (nfs://meaty.inside/var/nfs/export) mounted as /Volumes/meaty. The url there seems to support your phrasing "file systems somewhere farther down the food chain". |
Quote:
basically, the script needs to account for the following conditions:
the first is easy. the second ought to be handled (and excluded) by the scriptlet I gave above (unless there's an error in the code). the third is problematic: ld doesn't have a trigger for when a file system is unmounted, and rsync is unaware of the file system change. |
Quote:
|
Quote:
If I'm following that lastMounted assignment correctly, this might be how i'd do it: lastMounted=$(mount -t hfs |sed '$!d;s:^/.*/::;s: (hfs.*)$::') I'm not clear on what 'triggers' your main script. Does it run all the time (via either periodic calls or some sleep period) to regularly check for lastMounted... and then call some rsync subroutine if criteria is satisfied? As cwtnospam points out, launchd can do some of that work nicely. See man launchd.plist (or google, search here, etc.), for keywords like: StartOnMount |
Quote:
and oy vey - sed! is there an advantage to using it over the awk? because I REALLY hate sed... :o |
Quote:
[[ -d $target ]] || exit 1 rsync . . . ...that: a) rsync would never even get called unless the target folder is there, and b) once rsync does get called, wouldn't Finder *see* that the disk is "busy"? Quote:
Quote:
[i will note though that --as written-- sed is doing the work of both awk and split.] Or is that "split" one of awk's built-in tools? (as opposed to /usr/bin/split) |
Quote:
I've been considering writing a second launchd job that only runs when the backup job is activated (using KeepAlive when OtherJobEnabled) that checks periodically that the Backup folder has an inode of 2, and squelches the backup if it doesn't. I'll see how that works out, because I've never used KeepAlive before... and yes, split is one of awk's functions, though I may just rewrite that to be a grep test, since I don't really need a result returned, just a boolean test. |
Quote:
Just stop making folders in /Volumes! (yes... you) ;) i.e., as long as there is no folder there *now* - - - then [[ -d $target ]] || exit 1 rsync . . . stops rsync from making one. Have you *tried* this yet? |
ok, well I threw the line in (since I can't see how it would hurt). :)
|
Quote:
it was done in such a way that $target is defined. ;) |
Quote:
|
... touché
|
| All times are GMT -5. The time now is 05:46 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.