rsync as root - does it change the ownership of synced files?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















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?










share|improve this question


























    1















    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?










    share|improve this question
























      1












      1








      1








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 4 at 8:42









      Steve WrightSteve Wright

      112




      112




















          2 Answers
          2






          active

          oldest

          votes


















          1














          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)







          share|improve this answer

























          • 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 the mkusb 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


















          1














          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 let rsync 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.





          share|improve this answer

























          • 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










          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
          );



          );













          draft saved

          draft discarded


















          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









          1














          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)







          share|improve this answer

























          • 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 the mkusb 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















          1














          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)







          share|improve this answer

























          • 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 the mkusb 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













          1












          1








          1







          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)







          share|improve this answer















          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)








          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 the mkusb 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











          • 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 the mkusb 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













          1














          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 let rsync 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.





          share|improve this answer

























          • 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















          1














          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 let rsync 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.





          share|improve this answer

























          • 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













          1












          1








          1







          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 let rsync 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.





          share|improve this answer















          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 let rsync 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.






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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

















          • 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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?