Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #239894
| From | john doe <johndoe65534@mail.com> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: copy directory tree, mapping to new owners |
| Date | 2021-09-12 09:00 +0200 |
| Message-ID | <CWrD3-56O-1@gated-at.bofh.it> (permalink) |
| References | <CWlQZ-11P-1@gated-at.bofh.it> <CWm0F-15d-3@gated-at.bofh.it> <CWmN3-1EN-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 9/12/2021 3:45 AM, Richard Hector wrote:
> On 12/09/21 12:52 pm, Greg Wooledge wrote:
>> On Sun, Sep 12, 2021 at 12:43:29PM +1200, Richard Hector wrote:
>>> The context of my question is that I'm creating (or updating) a test
>>> copy of
>>> a website. The files are owned by one of two owners, depending on
>>> whether
>>> they were written by the server (actually php-fpm).
>>>
>>> To do that, I want all the permissions to remain the same, but the
>>> ownership
>>> should be changed according to a provided map. For example, if the
>>> old file
>>> was owned by 'mysite', the copy should be owned by 'mysite_test'. If
>>> the old
>>> file was owned by 'mysite-run' (the user php runs as), the copy
>>> should be
>>> owned by 'mysite_test-run' (if that has to be 'mysite-run_test' to make
>>> things easier, I can live with that).
>>
>> cd /src
>> mkdir -p /dest
>> rsync -a . /dest/ # The trailing / matters.
>> cd /dest
>> find . -user mysite -exec chown mysite_test {} +
>> find . -user mysite-run -exec chown mysite-run_test {} +
>
> Thanks, that looks reasonable. It does mean, though, that the files
> exist for a while with the wrong ownership. That probably doesn't
> matter, but somehow 'feels wrong' to me.
>
If you are doing this in a script, I would use a temporary directory.
That way, in case of failure the destination directory is not rongly
modified.
EG:
$ rsync <src-dir> <tmp-dir>
Make <tmp-dir> the way you want it to be.
$ rsync <tmp-dir> <dest-dir>
Given that you want to change the ownership, you may want to emulate the
options implied by '-a' but without the ownership option ('-o').
> My habits would also lead me to do all of the above from above the two
> directories in question (in my case, /srv - for /srv/mysite/doc_root and
> /srv/mysite_test/doc_root) So:
>
> cd /srv
>
> # actually not necessary? rsync will create it
> mkdir -p mysite_test/doc_root
>
> # The trailing / matters. Does it matter on the source as well?
According to the man page it does (1):
"CWrsync -avz foo:src/bar/ /data/tmp
A trailing slash on the source changes this behavior to avoid creating
an additional directory level at the destination. You can think of a
trailing / on a source as meaning lqcopy the contents"
> # I generally include it.
In a script, you need to be sure what the cmd does do or not do!!! :)
> rsync -a mysite/doc_root/ mysite_test/doc_root/ # The trailing /
> matters.
>
> find mysite_dest -user mysite -exec chown mysite_test {} +
>
> # I prefer mysite_test-run; it keeps consistency with
> # the ${sitename}-run pattern used elsewhere
> find mysite_dest -user mysite-run -exec chown mysite_test-run {} +
>
> Have I broken anything there?
>
Not that I can see but testing will tell!
>> This is what I would do. And I would do it *interactively*.
>>
>> If you insist on making a script, then it will be slightly more
>> complicated, because you'll need to add error checking.
>
> The trouble with doing it interactively, when it needs to be done many
> times (and on several sites), is that each time there's opportunity to
> make a mistake. And it means the process needs to be documented
> separately from the script.
>
> In fact, I'd incorporate the above in a larger script, which does things
> like copying the database (and changing the db name in the site config).
>
> Error checking in shell scripts is something I certainly need to learn
At the very least, '<cmd> ['&&'|'||'] handle the error>.
If you use Bash and don't need to be POSIX compliant and /or portable
you can be a bit more creative.
> and practice more - I tend to rely somewhat on 'knowing' what I'm
> working with, which is probably not a good idea.
>
Yes in a script it is like shooting yourself in the foot.
1) https://linux.die.net/man/1/rsync
--
John Doe
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
copy directory tree, mapping to new owners Richard Hector <richard@walnut.gen.nz> - 2021-09-12 02:50 +0200
Re: copy directory tree, mapping to new owners Greg Wooledge <greg@wooledge.org> - 2021-09-12 03:00 +0200
Re: copy directory tree, mapping to new owners Richard Hector <richard@walnut.gen.nz> - 2021-09-12 03:50 +0200
Re: copy directory tree, mapping to new owners john doe <johndoe65534@mail.com> - 2021-09-12 09:00 +0200
Re: copy directory tree, mapping to new owners Andrei POPESCU <andreimpopescu@gmail.com> - 2021-09-12 12:30 +0200
Re: copy directory tree, mapping to new owners Richard Hector <richard@walnut.gen.nz> - 2021-09-13 01:50 +0200
Re: copy directory tree, mapping to new owners <tomas@tuxteam.de> - 2021-09-13 09:10 +0200
Re: copy directory tree, mapping to new owners Richard Hector <richard@walnut.gen.nz> - 2021-09-14 08:20 +0200
Re: copy directory tree, mapping to new owners <tomas@tuxteam.de> - 2021-09-14 09:00 +0200
Re: copy directory tree, mapping to new owners David Wright <deblis@lionunicorn.co.uk> - 2021-09-14 15:50 +0200
Re: copy directory tree, mapping to new owners Richard Hector <richard@walnut.gen.nz> - 2021-09-15 01:00 +0200
Re: copy directory tree, mapping to new owners l0f4r0@tuta.io - 2021-09-12 09:00 +0200
Re: copy directory tree, mapping to new owners Curt <curty@free.fr> - 2021-09-12 16:30 +0200
Re: copy directory tree, mapping to new owners l0f4r0@tuta.io - 2021-09-12 18:40 +0200
Re: copy directory tree, mapping to new owners Richard Hector <richard@walnut.gen.nz> - 2021-09-13 01:50 +0200
Re: copy directory tree, mapping to new owners l0f4r0@tuta.io - 2021-09-12 09:20 +0200
Re: copy directory tree, mapping to new owners Teemu Likonen <tlikonen@iki.fi> - 2021-09-12 09:50 +0200
Re: copy directory tree, mapping to new owners <tomas@tuxteam.de> - 2021-09-12 10:10 +0200
Re: copy directory tree, mapping to new owners Richard Hector <richard@walnut.gen.nz> - 2021-09-13 02:10 +0200
csiph-web