![소유자와 권한을 동일하게 유지하면서 폴더를 복사하는 방법은 무엇입니까?](https://linux55.com/image/24168/%EC%86%8C%EC%9C%A0%EC%9E%90%EC%99%80%20%EA%B6%8C%ED%95%9C%EC%9D%84%20%EB%8F%99%EC%9D%BC%ED%95%98%EA%B2%8C%20%EC%9C%A0%EC%A7%80%ED%95%98%EB%A9%B4%EC%84%9C%20%ED%8F%B4%EB%8D%94%EB%A5%BC%20%EB%B3%B5%EC%82%AC%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
그래서 다음과 같이 홈 폴더를 외부 드라이브에 복사하여 백업할 계획입니다.
sudo cp -r /home/my_home /media/backup/my_home
결과적으로 외장 드라이브의 모든 폴더가 이제 소유됩니다 . 원래 소유권과 권한을 유지하려면 root:root
어떻게 해야 합니까 ?cp
답변1
sudo cp -rp /home/my_home /media/backup/my_home
cp 맨페이지에서:
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,timestamps),
if possible additional attributes: context, links, xattr, all
답변2
을 사용할 수도 있습니다 rsync
.
sudo rsync -a /home/my_home/ /media/backup/my_home/
rsync
맨페이지 에서 :
-a, --archive
This is equivalent to -rlptgoD. It is a quick way of saying you want
recursion and want to preserve almost everything (with -H being a notable
omission). The only exception to the above equivalence is when
--files-from is specified, in which case -r is not implied.
Note that -a does not preserve hardlinks, because finding multiply-linked
files is expensive. You must separately specify -H.
cp
다음을 비교하려면 이 질문을 참조하세요 rsync
.https://stackoverflow.com/q/6339287/406686
뒤에 오는 슬래시에 주의하세요(자세한 내용은 맨페이지 참조).
답변3
cp -a
Where -a
의 약어 --archive
— 기본적으로 디렉터리를 있는 그대로 복사합니다. 파일은 모든 속성을 유지하며 기호 링크는 역참조되지 않습니다( -d
).
에서 man cp
:
-a, --archive
same as -dR --preserve=all
답변4
다음을 수행할 수 있습니다.
tar cf - my_home | (cd /media/backup; sudo tar xf - )
tar
권한, 소유권, 디렉터리 구조는 그대로 유지하되 모든 것을 바이트 스트림으로 변환하세요. 디렉토리를 변경한 다음 tar
변환을 되돌리는 "하위 쉘"(괄호 안의 명령)을 실행합니다. 바이트 문자열은 올바른 소유권과 권한을 가진 디렉터리와 파일이 됩니다.