rsync 括弧拡張の洞察

rsync 括弧拡張の洞察

Ubuntu 14.04 インストールを外部ディスクのディレクトリと同期したい。

実は私は拡張ドライブから起動し、マウントした内部ドライブにUbuntu 14.04ディストリビューションの部分的なコピーを作成したいのです。/media/kenn/c2d1b866/

マウント先のディレクトリ/mnt/RESTORE/backup_14.04.5

私は様々な組み合わせを試しましたrsync次のようなコマンド

sudo rsync -avr /media/kenn/c2d1b866/{bin/,sbin/,usr/,opt/,lib/,var/,etc/,srv/,libx32/,lib64/,run/,boot/,proc/,sys/,dev/} /mnt/RESTORE/backup_14.04.5

sudo rsync -avr /media/kenn/c2d1b866/{bin/,sbin/,usr/,opt/,lib/,var/,etc/,srv/,libx32/,lib64/,run/,boot/,proc/,sys/,dev/} /mnt/RESTORE/backup_14.04.5/

sudo rsync -avr /media/kenn/c2d1b866/{"bin/","sbin/","usr/","opt/","lib/","var/","etc/","srv/","libx32/","lib64/","run/","boot/","proc/","sys/","dev/"} /mnt/RESTORE/backup_14.04.5

他にもいろいろありますが、私は失敗しました。なぜなら、括弧の展開が期待通りに機能しなかったからです。括弧のディレクトリ内のすべてのファイルを/mnt/RESTORE/backup_14.04.5、つまりルートディレクトリにコピーします。backup_14.04.5

どうすればコピーできますかbin/,sbin/,usr/,opt/,lib/,var/,etc/,srv/,libx32/,lib64/,run/,boot/,proc/,sys/,dev/

/media/kenn/c2d1b866/の中へ/mnt/RESTORE/backup_14.04.5

答え1

括弧内の全てのファイルをコピーします/mnt/RESTORE/backup_14.04.5

これはrsyncソースパスの末尾にスラッシュがある場合の動作です/man rsync:

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 "copy the contents of this directory"
as opposed to "copy the directory by  name",  but  in  both  cases  the
attributes   of   the  containing  directory  are  transferred  to  the
containing directory on the destination.

ディレクトリをコピーするには、以下を省略します/

sudo rsync -avr /media/kenn/c2d1b866/{bin,sbin,usr,opt,lib,var,etc,srv,libx32,lib64,run,boot,proc,sys,dev} /mnt/RESTORE/backup_14.04.5

関連情報