rsync as root - does it change the ownership of synced files?
Clash Royale CLAN TAG#URR8PPP
I'm going to be using rsync to sync an old home folder onto a backup drive. I'm thinking of using rsync as root. Is there a way to avoid changing the ownership of the files etc I copy?
rsync backup root
add a comment |
I'm going to be using rsync to sync an old home folder onto a backup drive. I'm thinking of using rsync as root. Is there a way to avoid changing the ownership of the files etc I copy?
rsync backup root
add a comment |
I'm going to be using rsync to sync an old home folder onto a backup drive. I'm thinking of using rsync as root. Is there a way to avoid changing the ownership of the files etc I copy?
rsync backup root
I'm going to be using rsync to sync an old home folder onto a backup drive. I'm thinking of using rsync as root. Is there a way to avoid changing the ownership of the files etc I copy?
rsync backup root
rsync backup root
asked Jan 4 at 8:42
Steve WrightSteve Wright
112
112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use the -o
and -g
options. From the rsync
manual (man rsync
):
-o
,--owner
preserve owner (super-user only)
-g
,--group
preserve group
Going one step further, an option commonly used with rsync
is the -a
/--archive
option. This option implies -rlptgoD
, which are the following options:
-r
,--recursive
recurse into directories
-l
,--links
copy symlinks as symlinks
-p
,--perms
preserve permissions
-t
,--times
preserve modification times
-D
same as--devices --specials
(preserve device files, preserve special files)
I'm not a big fan of -a. Back when I used Cygwin, it mw
– Steve Wright
Jan 4 at 10:04
It messed up a bunch of file's I was trying to do this same thing with. Of course Cygwin's rsync was probably the same as the one from BSD (I know its tar w
– Steve Wright
Jan 4 at 10:07
I know its tar was.
– Steve Wright
Jan 4 at 10:07
@SteveWright, I have a good experience of the-a
option. I use it often for home directories, even as part of themkusb
tool for persistent live drives.
– sudodus
Jan 4 at 10:09
1
A also with Cygwin, it didn't help that NTFS, while somewhat close to one, still isn't a Lunix filesystem.
– Steve Wright
Jan 4 at 10:10
|
show 1 more comment
I use the following command line to preserve 'everything', file content, ownership and permissions of files, directories, symbolic links etc. This way I have been able to copy a system to a new drive and make it work in another computer. OK, I had to fix the bootloader too, but it works well with copying of the file content, ownership and permissions.
- Please notice the trailing slash on the source directory, and read about it in
man rsync
.
rsync -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 "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 contain‐
ing directory on the destination. In other words, each of the follow‐
ing commands copies the files in the same way, including their setting
of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo
Note also that host and module references don’t require a trailing
slash to copy the contents of the default directory. For example, both
of these copy the remote directory’s contents into "/dest":
rsync -av host: /dest
rsync -av host::module /dest
You can also use rsync in local-only mode, where both the source and
destination don’t have a ’:’ in the name. In this case it behaves like
an improved copy command.
-n
, start with a 'dry run', to check that things look correct.sudo rsync -Havn source/ target
Remove the option (
-n
) and letrsync
do its job.sudo rsync -Hav source/ target
It will check if each directory/file in the target exists and is up to date, and only copy what needs to be updated (in a backup scenario).
-H
keeps track of hard links (which save drive space), but makes the copy process slower (the reason that it is not included in-a
-a
is the standard archive option for backup purposes, which preserves 'everything' about the files in the file system (except hard links).-v
is the classic verbose option, which prints all files that are to be copied. There are other options to monitor the progress, that you may like better. You may prefer to turn off verbosity, but it is good in the early stages to check that things work are expected.
I like it. I think I'll go with it.
– Steve Wright
Jan 4 at 10:08
@SteveWright, Good luck :-)
– sudodus
Jan 4 at 10:10
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492413%2frsync-as-root-does-it-change-the-ownership-of-synced-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the -o
and -g
options. From the rsync
manual (man rsync
):
-o
,--owner
preserve owner (super-user only)
-g
,--group
preserve group
Going one step further, an option commonly used with rsync
is the -a
/--archive
option. This option implies -rlptgoD
, which are the following options:
-r
,--recursive
recurse into directories
-l
,--links
copy symlinks as symlinks
-p
,--perms
preserve permissions
-t
,--times
preserve modification times
-D
same as--devices --specials
(preserve device files, preserve special files)
I'm not a big fan of -a. Back when I used Cygwin, it mw
– Steve Wright
Jan 4 at 10:04
It messed up a bunch of file's I was trying to do this same thing with. Of course Cygwin's rsync was probably the same as the one from BSD (I know its tar w
– Steve Wright
Jan 4 at 10:07
I know its tar was.
– Steve Wright
Jan 4 at 10:07
@SteveWright, I have a good experience of the-a
option. I use it often for home directories, even as part of themkusb
tool for persistent live drives.
– sudodus
Jan 4 at 10:09
1
A also with Cygwin, it didn't help that NTFS, while somewhat close to one, still isn't a Lunix filesystem.
– Steve Wright
Jan 4 at 10:10
|
show 1 more comment
You can use the -o
and -g
options. From the rsync
manual (man rsync
):
-o
,--owner
preserve owner (super-user only)
-g
,--group
preserve group
Going one step further, an option commonly used with rsync
is the -a
/--archive
option. This option implies -rlptgoD
, which are the following options:
-r
,--recursive
recurse into directories
-l
,--links
copy symlinks as symlinks
-p
,--perms
preserve permissions
-t
,--times
preserve modification times
-D
same as--devices --specials
(preserve device files, preserve special files)
I'm not a big fan of -a. Back when I used Cygwin, it mw
– Steve Wright
Jan 4 at 10:04
It messed up a bunch of file's I was trying to do this same thing with. Of course Cygwin's rsync was probably the same as the one from BSD (I know its tar w
– Steve Wright
Jan 4 at 10:07
I know its tar was.
– Steve Wright
Jan 4 at 10:07
@SteveWright, I have a good experience of the-a
option. I use it often for home directories, even as part of themkusb
tool for persistent live drives.
– sudodus
Jan 4 at 10:09
1
A also with Cygwin, it didn't help that NTFS, while somewhat close to one, still isn't a Lunix filesystem.
– Steve Wright
Jan 4 at 10:10
|
show 1 more comment
You can use the -o
and -g
options. From the rsync
manual (man rsync
):
-o
,--owner
preserve owner (super-user only)
-g
,--group
preserve group
Going one step further, an option commonly used with rsync
is the -a
/--archive
option. This option implies -rlptgoD
, which are the following options:
-r
,--recursive
recurse into directories
-l
,--links
copy symlinks as symlinks
-p
,--perms
preserve permissions
-t
,--times
preserve modification times
-D
same as--devices --specials
(preserve device files, preserve special files)
You can use the -o
and -g
options. From the rsync
manual (man rsync
):
-o
,--owner
preserve owner (super-user only)
-g
,--group
preserve group
Going one step further, an option commonly used with rsync
is the -a
/--archive
option. This option implies -rlptgoD
, which are the following options:
-r
,--recursive
recurse into directories
-l
,--links
copy symlinks as symlinks
-p
,--perms
preserve permissions
-t
,--times
preserve modification times
-D
same as--devices --specials
(preserve device files, preserve special files)
edited Jan 4 at 9:03
Kusalananda
124k16235386
124k16235386
answered Jan 4 at 8:59
HaxielHaxiel
1,733410
1,733410
I'm not a big fan of -a. Back when I used Cygwin, it mw
– Steve Wright
Jan 4 at 10:04
It messed up a bunch of file's I was trying to do this same thing with. Of course Cygwin's rsync was probably the same as the one from BSD (I know its tar w
– Steve Wright
Jan 4 at 10:07
I know its tar was.
– Steve Wright
Jan 4 at 10:07
@SteveWright, I have a good experience of the-a
option. I use it often for home directories, even as part of themkusb
tool for persistent live drives.
– sudodus
Jan 4 at 10:09
1
A also with Cygwin, it didn't help that NTFS, while somewhat close to one, still isn't a Lunix filesystem.
– Steve Wright
Jan 4 at 10:10
|
show 1 more comment
I'm not a big fan of -a. Back when I used Cygwin, it mw
– Steve Wright
Jan 4 at 10:04
It messed up a bunch of file's I was trying to do this same thing with. Of course Cygwin's rsync was probably the same as the one from BSD (I know its tar w
– Steve Wright
Jan 4 at 10:07
I know its tar was.
– Steve Wright
Jan 4 at 10:07
@SteveWright, I have a good experience of the-a
option. I use it often for home directories, even as part of themkusb
tool for persistent live drives.
– sudodus
Jan 4 at 10:09
1
A also with Cygwin, it didn't help that NTFS, while somewhat close to one, still isn't a Lunix filesystem.
– Steve Wright
Jan 4 at 10:10
I'm not a big fan of -a. Back when I used Cygwin, it mw
– Steve Wright
Jan 4 at 10:04
I'm not a big fan of -a. Back when I used Cygwin, it mw
– Steve Wright
Jan 4 at 10:04
It messed up a bunch of file's I was trying to do this same thing with. Of course Cygwin's rsync was probably the same as the one from BSD (I know its tar w
– Steve Wright
Jan 4 at 10:07
It messed up a bunch of file's I was trying to do this same thing with. Of course Cygwin's rsync was probably the same as the one from BSD (I know its tar w
– Steve Wright
Jan 4 at 10:07
I know its tar was.
– Steve Wright
Jan 4 at 10:07
I know its tar was.
– Steve Wright
Jan 4 at 10:07
@SteveWright, I have a good experience of the
-a
option. I use it often for home directories, even as part of the mkusb
tool for persistent live drives.– sudodus
Jan 4 at 10:09
@SteveWright, I have a good experience of the
-a
option. I use it often for home directories, even as part of the mkusb
tool for persistent live drives.– sudodus
Jan 4 at 10:09
1
1
A also with Cygwin, it didn't help that NTFS, while somewhat close to one, still isn't a Lunix filesystem.
– Steve Wright
Jan 4 at 10:10
A also with Cygwin, it didn't help that NTFS, while somewhat close to one, still isn't a Lunix filesystem.
– Steve Wright
Jan 4 at 10:10
|
show 1 more comment
I use the following command line to preserve 'everything', file content, ownership and permissions of files, directories, symbolic links etc. This way I have been able to copy a system to a new drive and make it work in another computer. OK, I had to fix the bootloader too, but it works well with copying of the file content, ownership and permissions.
- Please notice the trailing slash on the source directory, and read about it in
man rsync
.
rsync -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 "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 contain‐
ing directory on the destination. In other words, each of the follow‐
ing commands copies the files in the same way, including their setting
of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo
Note also that host and module references don’t require a trailing
slash to copy the contents of the default directory. For example, both
of these copy the remote directory’s contents into "/dest":
rsync -av host: /dest
rsync -av host::module /dest
You can also use rsync in local-only mode, where both the source and
destination don’t have a ’:’ in the name. In this case it behaves like
an improved copy command.
-n
, start with a 'dry run', to check that things look correct.sudo rsync -Havn source/ target
Remove the option (
-n
) and letrsync
do its job.sudo rsync -Hav source/ target
It will check if each directory/file in the target exists and is up to date, and only copy what needs to be updated (in a backup scenario).
-H
keeps track of hard links (which save drive space), but makes the copy process slower (the reason that it is not included in-a
-a
is the standard archive option for backup purposes, which preserves 'everything' about the files in the file system (except hard links).-v
is the classic verbose option, which prints all files that are to be copied. There are other options to monitor the progress, that you may like better. You may prefer to turn off verbosity, but it is good in the early stages to check that things work are expected.
I like it. I think I'll go with it.
– Steve Wright
Jan 4 at 10:08
@SteveWright, Good luck :-)
– sudodus
Jan 4 at 10:10
add a comment |
I use the following command line to preserve 'everything', file content, ownership and permissions of files, directories, symbolic links etc. This way I have been able to copy a system to a new drive and make it work in another computer. OK, I had to fix the bootloader too, but it works well with copying of the file content, ownership and permissions.
- Please notice the trailing slash on the source directory, and read about it in
man rsync
.
rsync -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 "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 contain‐
ing directory on the destination. In other words, each of the follow‐
ing commands copies the files in the same way, including their setting
of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo
Note also that host and module references don’t require a trailing
slash to copy the contents of the default directory. For example, both
of these copy the remote directory’s contents into "/dest":
rsync -av host: /dest
rsync -av host::module /dest
You can also use rsync in local-only mode, where both the source and
destination don’t have a ’:’ in the name. In this case it behaves like
an improved copy command.
-n
, start with a 'dry run', to check that things look correct.sudo rsync -Havn source/ target
Remove the option (
-n
) and letrsync
do its job.sudo rsync -Hav source/ target
It will check if each directory/file in the target exists and is up to date, and only copy what needs to be updated (in a backup scenario).
-H
keeps track of hard links (which save drive space), but makes the copy process slower (the reason that it is not included in-a
-a
is the standard archive option for backup purposes, which preserves 'everything' about the files in the file system (except hard links).-v
is the classic verbose option, which prints all files that are to be copied. There are other options to monitor the progress, that you may like better. You may prefer to turn off verbosity, but it is good in the early stages to check that things work are expected.
I like it. I think I'll go with it.
– Steve Wright
Jan 4 at 10:08
@SteveWright, Good luck :-)
– sudodus
Jan 4 at 10:10
add a comment |
I use the following command line to preserve 'everything', file content, ownership and permissions of files, directories, symbolic links etc. This way I have been able to copy a system to a new drive and make it work in another computer. OK, I had to fix the bootloader too, but it works well with copying of the file content, ownership and permissions.
- Please notice the trailing slash on the source directory, and read about it in
man rsync
.
rsync -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 "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 contain‐
ing directory on the destination. In other words, each of the follow‐
ing commands copies the files in the same way, including their setting
of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo
Note also that host and module references don’t require a trailing
slash to copy the contents of the default directory. For example, both
of these copy the remote directory’s contents into "/dest":
rsync -av host: /dest
rsync -av host::module /dest
You can also use rsync in local-only mode, where both the source and
destination don’t have a ’:’ in the name. In this case it behaves like
an improved copy command.
-n
, start with a 'dry run', to check that things look correct.sudo rsync -Havn source/ target
Remove the option (
-n
) and letrsync
do its job.sudo rsync -Hav source/ target
It will check if each directory/file in the target exists and is up to date, and only copy what needs to be updated (in a backup scenario).
-H
keeps track of hard links (which save drive space), but makes the copy process slower (the reason that it is not included in-a
-a
is the standard archive option for backup purposes, which preserves 'everything' about the files in the file system (except hard links).-v
is the classic verbose option, which prints all files that are to be copied. There are other options to monitor the progress, that you may like better. You may prefer to turn off verbosity, but it is good in the early stages to check that things work are expected.
I use the following command line to preserve 'everything', file content, ownership and permissions of files, directories, symbolic links etc. This way I have been able to copy a system to a new drive and make it work in another computer. OK, I had to fix the bootloader too, but it works well with copying of the file content, ownership and permissions.
- Please notice the trailing slash on the source directory, and read about it in
man rsync
.
rsync -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 "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 contain‐
ing directory on the destination. In other words, each of the follow‐
ing commands copies the files in the same way, including their setting
of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo
Note also that host and module references don’t require a trailing
slash to copy the contents of the default directory. For example, both
of these copy the remote directory’s contents into "/dest":
rsync -av host: /dest
rsync -av host::module /dest
You can also use rsync in local-only mode, where both the source and
destination don’t have a ’:’ in the name. In this case it behaves like
an improved copy command.
-n
, start with a 'dry run', to check that things look correct.sudo rsync -Havn source/ target
Remove the option (
-n
) and letrsync
do its job.sudo rsync -Hav source/ target
It will check if each directory/file in the target exists and is up to date, and only copy what needs to be updated (in a backup scenario).
-H
keeps track of hard links (which save drive space), but makes the copy process slower (the reason that it is not included in-a
-a
is the standard archive option for backup purposes, which preserves 'everything' about the files in the file system (except hard links).-v
is the classic verbose option, which prints all files that are to be copied. There are other options to monitor the progress, that you may like better. You may prefer to turn off verbosity, but it is good in the early stages to check that things work are expected.
edited Jan 4 at 10:02
answered Jan 4 at 9:29
sudodussudodus
1,30616
1,30616
I like it. I think I'll go with it.
– Steve Wright
Jan 4 at 10:08
@SteveWright, Good luck :-)
– sudodus
Jan 4 at 10:10
add a comment |
I like it. I think I'll go with it.
– Steve Wright
Jan 4 at 10:08
@SteveWright, Good luck :-)
– sudodus
Jan 4 at 10:10
I like it. I think I'll go with it.
– Steve Wright
Jan 4 at 10:08
I like it. I think I'll go with it.
– Steve Wright
Jan 4 at 10:08
@SteveWright, Good luck :-)
– sudodus
Jan 4 at 10:10
@SteveWright, Good luck :-)
– sudodus
Jan 4 at 10:10
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492413%2frsync-as-root-does-it-change-the-ownership-of-synced-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown