Rsync コマンドの問題、所有者とグループの権限が変更されない

Rsync コマンドの問題、所有者とグループの権限が変更されない

所有者とグループを設定しようとしていますrsyncが、機能していないようです。

コマンドは次のとおりです:

sudo rsync -rlptDvz --owner=cmsseren --group=cmsseren /home/serena/public_html/ -e ssh root@ip:/home/cmsseren/public_html2/

ファイルは正しく同期されますが、所有者とグループは変更されないようです。

答え1

正常に動作しているようです。--ownerとを使用し--group保存する(未設定) 所有者とグループ名...つまり、転送後に変更したくないということです。

これらのオプションを使用しない場合、ユーザーとグループは受信側で呼び出したユーザーに変更されます。他のユーザーを指定する場合は、chownスクリプトにコマンドを追加する必要があります。

-o, --owner
    This option causes rsync to set the owner of the destination file to be 
    the same as  the source file, but only if the receiving rsync is being run 
    as the super-user (see also the --super and --fake-super options). Without 
    this option, the owner of new and/or transferred files are set to the invoking 
    user on the receiving side...

-g, --group
    This option causes rsync to set the group of the destination file to be the same as 
    the source file. If the receiving program is not running as the super-user (or if
    --no-super was specified), only groups that the invoking user on the receiving side
    is a member of will be preserved. Without this option, the group is set to the default
    group of the invoking user on the receiving side...

rsyncコマンド

答え2

バージョン 3.1.0rsyncはトーマスによって導入され--usermap言及--groupmapされたが、便利なオプションも--chown、これはあなたのシナリオに適しています。

--chown=USER:GROUP
    This option forces all files to be owned by USER with group GROUP.
    This  is  a  simpler  interface  than  using  --usermap  and  --groupmap directly,
    but  it  is implemented using those options internally, so you cannot mix them.
    If either the USER or GROUP is empty, no mapping for the omitted user/group will
    occur.  If GROUP is empty, the trailing colon may be omitted, but if USER is
    empty, a leading colon must  be supplied.

    If you specify "--chown=foo:bar, this is exactly the same as specifying
    "--usermap=*:foo --groupmap=*:bar", only easier.

また、-oそして-gオプションは必須です。これらを除外すると、それぞれの属性は更新されませんが、エラーは発生しません。

rsync -og --chown=cmsseren:cmsseren [src] [dest]

これは間接的に言及されている。マニュアルページ--chownは、オプションが「内部的に--usermapと を使用して実装されている」ことを示しています--groupmap

この--usermapオプションを有効にするには、-o( --owner) オプションを使用する (または暗黙的に指定する) 必要があり、受信側はスーパーユーザーとして実行されている必要があります (オプションも参照--fake-super)。

--groupmapオプションを有効にするには、 -g( --groups) オプションを使用する (または暗黙的に指定する) 必要があり、受信者にはそのグループを設定する権限が必要です。

答え3

rsync の最新バージョン (少なくとも 3.1.1) では、「リモート所有権」を指定できます。

--usermap=tom:www-data

tom の所有権を www-data (別名 PHP/Nginx) に変更します。クライアントとして Mac を使用している場合は、brew を使用して最新バージョンにアップグレードします。サーバー上で、アーカイブ ソースをダウンロードして、「作成」します。

答え4

問題。SSH経由でクラウド VPS からリモート ファイルやディレクトリをバックアップすると、ローカル ホスト上のrsyncリモート所有権が維持されませんでした。owner:group

解決。

  1. リモート ホストから rsync されたファイル (ディレクトリなど) 用にローカル ホストにユーザーを作成します。
  2. ローカルホストrsyncコマンドをroot/として実行しますsudo
  3. ルートパスワード、SSH パスフレーズを手動で入力する必要があります。
# create local host system user(s) for those on remote host; see:
# https://wiki.archlinux.org/title/Users_and_groups#Example_adding_a_system_user

sudo rsync -aqP  -e "ssh -p 4321  \                   ## SSH port
    -i /home/victoria/.ssh/my-vps/id_rsa"  \          ## SSH credentials
    [email protected]_isp.com:/etc/default/solr.in.sh   ## rsync SRC (remote host)
    /<my home path>/backups/solr.in.sh  \             ## rsync DEST (local host)

テスト。

# -----------------------------------------------------------------------------
# REMOTE HOST (cloud VPS):

[me@vps1234]$ ls -l /etc/default/

  ...
  -rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh    ## ownership: root:solr
  ...

[me@vps1234]$ 

# -----------------------------------------------------------------------------
# LOCAL HOST:

The basic command for testing (with variations, following) is:

```bash
rm -f solr.in.sh;  \
rsync -aqP  \
    --rsync-path="sudo /bin/rsync"  \
    -e "ssh -p 4321  \
    -i /home/victoria/.ssh/my-vps/id_rsa"  \
    [email protected]_isp.com:/etc/default/solr.in.sh
    /<my home path>/backups/solr.in.sh;  \
ls -l solr.in.sh
# -----------------------------------------------------------------------------
# [TEST 1] rsync --rsync-path...

[victoria]$ rm -f solr.in.sh;  \
    rsync -aqP --rsync-path="sudo /bin/rsync"  \
      -e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
      /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh 

  -rw-r----- 1 victoria victoria 15079 Aug 12 20:35 solr.in.sh
            ## victoria victoria [incorrect]

[victoria]$
# -----------------------------------------------------------------------------
# [TEST 2] sudo rsync --rsync-path ; user "solr" not on local host so remote files
# in group "solr" renamed "git" on local host; tried rsync -og options: no effect

[victoria]$ rm -f solr.in.sh;  \
    sudo rsync -aqP --rsync-path="/usr/bin/rsync"  \
      -e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
    /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh 

  [sudo] password for victoria: 
  Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa': 

  -rw-r----- 1 root git 15079 Aug 12 20:35 solr.in.sh
            ## root:git [incorrect]

[victoria]$
# -----------------------------------------------------------------------------
# [CONFIGURE USERS]
# local host:

[victoria]$ cat /etc/passwd | grep solr     ## no such user
[victoria]$

# Create local host system user, for user on remote host:

[victoria@victoria backups]$ sudo useradd -r -s /usr/bin/nologin solr
  [sudo] password for victoria: 

[victoria]$ cat /etc/passwd | grep solr

  solr:x:980:980::/home/solr:/usr/bin/nologin

[victoria]$ ls -l /home/     ## check: useradd did not create /home/solr/

  total 52
  drwx------   2 root     root     16384 Mar  6  2015 lost+found
  drwxrwxr-x 178 victoria victoria 36864 Aug 13 10:09 victoria

[victoria]$
# -----------------------------------------------------------------------------
# [TEST 3: works] sudo --rsync-path...

[victoria]$ rm -f solr.in.sh;  \
    sudo rsync -aqP --rsync-path="/bin/rsync"  \
      -e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
      /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh 

  [sudo] password for victoria: 
  Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa': 

  -rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh
            ## root:solr [correct]

[victoria]$
# -----------------------------------------------------------------------------
# [TEST 4: works] No need for --rsync-path option:

[victoria@victoria backups]$ rm -f solr.in.sh;  \
    sudo rsync -aqP -e  \
      "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
      /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh

  [sudo] password for victoria:
  Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa':

  -rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh
            ## root:solr [correct]

[victoria@victoria backups]$

# -----------------------------------------------------------------------------

関連情報