2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rsync でディレクトリごとコピーする際に気をつけること~ディレクトリの中身をぶちまけないために

Posted at

結論

NG1.sh
rsync -r from_dir/from_file/ to_dir/

元ディレクトリのパスにケツスラッシュをつけると、from_dir はコピーされず、from_dir以下にあるフォルダ、ファイルがto_dir以下にコピーされる


├── from_dir
│   ├── from_1.txt
│   └── from_2.txt
└── to_dir
    ├── from_1.txt
    └── from_2.txt

そのため、

OK1.sh
rsync -r from_dir/from_file to_dir to_dir/

のようにケツスラッシュをなくすか、

OK2.sh
rsync -r from_dir/from_file/ to_dir to_dir/from_dir

のように、ケツスラッシュをつけた上でコピー後に保存したいdirの名前を明示的に書く必要がある(この場合はto_dirの方のケツスラッシュはつけてもつけなくてもOK

.
├── from_dir
│   ├── from_1.txt
│   └── from_2.txt
└── to_dir
    └── from_dir
        ├── from_1.txt
        └── from_2.txt

前書き

リモートでscpを使うのはもうやめた方がいいという話があるそうです。

また、スパコンにデータをコピーする際に途中でkill されたので、途中から実行することができる(ディレクトリを同期できる)scp ではなくrsyncを使ってみました

その結果rsync のディレクトリ指定の罠にハマって、コピーしたい元フォルダ以下のファイルを全てスパコンにぶちまけることになったので備忘録

scp とrsync の比較(引用)1

path 指定 scp rsync
from/files_dir/ dest/ NG NG
from/files_dir dest/ NG OK
from/files_dir/ dest/files_dir OK OK
from/files_dir dest/files_dir OK NG
from/files_dir/ dest/files_dir OK OK
from/files_dir dest/files_dir/ OK NG
  1. 引用元 http://oretachino.hatenablog.com/entry/2014/12/11/003815

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?