1 |
Dear Dale, |
2 |
|
3 |
On Friday 2 September 2022, 3.35am -0500, Dale wrote: |
4 |
|
5 |
> time rsync -auv --progress --delete /home/dale/Desktop/Crypt/Video/* |
6 |
> /mnt/10tb/Video/ |
7 |
|
8 |
What is going on here is due to a subtle interplay of rsync’s syntax and |
9 |
shell wildcard expansion. You can read about the details of rsync |
10 |
syntax in its man page, but I’ll illustrate here: |
11 |
|
12 |
rsync has two ways to specify a source directory. |
13 |
|
14 |
1. Without a trailing slash: `rsync <options> path1/source path2/dest`. |
15 |
This syncs path1/source -> path2/dest/source. |
16 |
|
17 |
2. With a trailing slash: `rsync <options> path1/source/ path2/dest`. |
18 |
This syncs path1/source -> path2/dest. |
19 |
|
20 |
Note that the two ways lead to different target directories getting |
21 |
synced with the source directory. I think the command you are looking |
22 |
for is therefore |
23 |
|
24 |
time rsync -auv --progress --delete /home/dale/Desktop/Crypt/Video /mnt/10tb |
25 |
|
26 |
or |
27 |
|
28 |
time rsync -auv --progress --delete /home/dale/Desktop/Crypt/Video/ |
29 |
/mnt/10tb/Video |
30 |
|
31 |
NOTE: I have not tested these commands, I would advise you to run them |
32 |
with --dry-run first. |
33 |
|
34 |
Now, why is your original command not deleting the old subdirectory? |
35 |
Let me illustrate this with another example. Suppose we have the same |
36 |
directories as in my first example, path1/source and path2/dest. Now |
37 |
suppose path1/source contains subdirectories foo and bar. These were |
38 |
synced with path2/dest, which therefore also contains foo and bar. Now |
39 |
you rename foo to foo-1 in your source directory. So we have |
40 |
|
41 |
$ ls path1/source |
42 |
foo-1 |
43 |
bar |
44 |
|
45 |
$ ls path2/dest |
46 |
foo |
47 |
bar |
48 |
|
49 |
When you type path1/source/*, it therefore gets expanded to: |
50 |
path1/source/foo-1 path1/source/bar |
51 |
|
52 |
That’s two different source directories, rsync will sync each |
53 |
separately to a subdirectory of the same name (because there is no |
54 |
trailing slash) under path2/dest: |
55 |
|
56 |
path1/source/foo-1 -> path2/dest/foo-1 |
57 |
path1/source/bar -> path2/dest/bar |
58 |
|
59 |
And what about path2/dest/foo? Well, it is not included in these two |
60 |
syncs, so rsync leaves it untouched. The --delete option only affects |
61 |
what is under your sources and targets, here foo-1 and bar, not foo. |
62 |
|
63 |
So, to conclude, what you probably want is to use one of the rsync |
64 |
commands I listed above, which sync the entire source directory with the |
65 |
target, and will clean up anything under the target that is not under |
66 |
the source. Instead, what your old command was doing is to look at |
67 |
every subdirectory and file of the source one by one, which will miss |
68 |
anything in the target that does not have a corresponding item in the |
69 |
source. |
70 |
|
71 |
I hope this helps, |
72 |
|
73 |
Sincerely, |
74 |
|
75 |
Bas |
76 |
|
77 |
|
78 |
-- |
79 |
Sebastiaan L. Zoutendijk • slzoutendijk@×××××.com |