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?
You can use the
-g options. From the
rsync manual (
--ownerpreserve owner (super-user only)
Going one step further, an option commonly used with
rsync is the
--archive option. This option implies
-rlptgoD, which are the following options:
--recursiverecurse into directories
--linkscopy symlinks as symlinks
--timespreserve modification times
--devices --specials(preserve device files, preserve special files)
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
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
rsyncdo 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).
-Hkeeps track of hard links (which save drive space), but makes the copy process slower (the reason that it is not included in
-ais the standard archive option for backup purposes, which preserves 'everything' about the files in the file system (except hard links).
-vis 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.