How to rsync multiple source folders

Clash Royale CLAN TAG#URR8PPP
I want to rsync multiple sources and I wonder the best way to achieve that.
e.g.
/etc/fstab
/home/user/download
I thought about 3 solutions :
- Solution 1
multiple call to rsync
rsync -a /etc/fstab bkp
rsync -a /home/user/download bkp
con : harder to have agreggated stat
- Solution 2
create a tobackup folder that contains symlink, and use -L options
sync -aL /home/user/tobackup bkp
con : content to backup must not contain symlinks
- Solution 3
move files into to backup and create symlink in original location
rsync -a /home/user/tobackup bkp
con : some manual config
Which one do you recommend ?
Is there a better way ?
rsync
add a comment |
I want to rsync multiple sources and I wonder the best way to achieve that.
e.g.
/etc/fstab
/home/user/download
I thought about 3 solutions :
- Solution 1
multiple call to rsync
rsync -a /etc/fstab bkp
rsync -a /home/user/download bkp
con : harder to have agreggated stat
- Solution 2
create a tobackup folder that contains symlink, and use -L options
sync -aL /home/user/tobackup bkp
con : content to backup must not contain symlinks
- Solution 3
move files into to backup and create symlink in original location
rsync -a /home/user/tobackup bkp
con : some manual config
Which one do you recommend ?
Is there a better way ?
rsync
add a comment |
I want to rsync multiple sources and I wonder the best way to achieve that.
e.g.
/etc/fstab
/home/user/download
I thought about 3 solutions :
- Solution 1
multiple call to rsync
rsync -a /etc/fstab bkp
rsync -a /home/user/download bkp
con : harder to have agreggated stat
- Solution 2
create a tobackup folder that contains symlink, and use -L options
sync -aL /home/user/tobackup bkp
con : content to backup must not contain symlinks
- Solution 3
move files into to backup and create symlink in original location
rsync -a /home/user/tobackup bkp
con : some manual config
Which one do you recommend ?
Is there a better way ?
rsync
I want to rsync multiple sources and I wonder the best way to achieve that.
e.g.
/etc/fstab
/home/user/download
I thought about 3 solutions :
- Solution 1
multiple call to rsync
rsync -a /etc/fstab bkp
rsync -a /home/user/download bkp
con : harder to have agreggated stat
- Solution 2
create a tobackup folder that contains symlink, and use -L options
sync -aL /home/user/tobackup bkp
con : content to backup must not contain symlinks
- Solution 3
move files into to backup and create symlink in original location
rsync -a /home/user/tobackup bkp
con : some manual config
Which one do you recommend ?
Is there a better way ?
rsync
rsync
asked May 30 '17 at 23:21
user1437346user1437346
201124
201124
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can pass multiple source arguments.
rsync -a /etc/fstab /home/user/download bkp
This creates bkp/fstab and bkp/download, like the separate commands you gave. It may be desirable to preserve the source structure instead. To do this, use / as the source and use include-exclude rules to specify which files to copy. There are two ways to do this:
Explicitly include each file as well as each directory component leading to it, with
/***at the end of directories when you want to copy the whole directory tree:rsync -a
--include=/etc --include=/etc/fstab
--include=/home --include=/home/user --include='/home/user/download/***'
--exclude='*' / bkpInclude all top-level directories with
/*/(so that rsync will traverse/etcand/homewhen looking for files to copy) and second-level directories with/*/*/(for/home/user), but strip away directories in which no file gets copied. This is more convenient because you don't have to list parents explicitly. You could even use--prune-empty-dirs --include='*/'instead of counting the number of levels, but this is impractical here as rsync would traverse the whole filesystem to explore directories even though none of the include rules can match anything outside/etcand/home/user/download.rsync -a --prune-empty-dirs
--include='/*/' --include='/*/*/'
--include=/etc/fstab
--include='/home/user/download/***'
--exclude='*' / bkp
1
Great, but how to keep the directory structure inside bkp?
– Rodrigo
Sep 28 '17 at 18:23
I mean, bkp/etc/fstab and bkp/home/user/dowlonad? Or maybe /bkp/fstab and bkp/download?
– Rodrigo
Sep 28 '17 at 18:32
@Rodrigo I've edited my answer
– Gilles
Sep 28 '17 at 18:46
add a comment |
I really like Gilles' answer, however, I'd like to add that in my view the requirement to sync multiple folders while preserving the directory structure is best met by passing multiple source arguments in conjunction with the --relative option.
In this case, we could have something as follows:
rsync -aR /etc/fstab /home/user/download bkp
which would result in bkp/etc/fstab and bkp/home/user/download.
The best part about this is that (I believe since rsync v. 2.6.7) we can in essence control how much of the directory structure we want to replicate at the receiver.
(See the documentation on the --relative option here)
So e.g. if we did this
rsync -aR /home/./user1/download /home/./user2/download bkp
we would end up with bkp/user1/download and bkp/user2/download.
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%2f368210%2fhow-to-rsync-multiple-source-folders%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 pass multiple source arguments.
rsync -a /etc/fstab /home/user/download bkp
This creates bkp/fstab and bkp/download, like the separate commands you gave. It may be desirable to preserve the source structure instead. To do this, use / as the source and use include-exclude rules to specify which files to copy. There are two ways to do this:
Explicitly include each file as well as each directory component leading to it, with
/***at the end of directories when you want to copy the whole directory tree:rsync -a
--include=/etc --include=/etc/fstab
--include=/home --include=/home/user --include='/home/user/download/***'
--exclude='*' / bkpInclude all top-level directories with
/*/(so that rsync will traverse/etcand/homewhen looking for files to copy) and second-level directories with/*/*/(for/home/user), but strip away directories in which no file gets copied. This is more convenient because you don't have to list parents explicitly. You could even use--prune-empty-dirs --include='*/'instead of counting the number of levels, but this is impractical here as rsync would traverse the whole filesystem to explore directories even though none of the include rules can match anything outside/etcand/home/user/download.rsync -a --prune-empty-dirs
--include='/*/' --include='/*/*/'
--include=/etc/fstab
--include='/home/user/download/***'
--exclude='*' / bkp
1
Great, but how to keep the directory structure inside bkp?
– Rodrigo
Sep 28 '17 at 18:23
I mean, bkp/etc/fstab and bkp/home/user/dowlonad? Or maybe /bkp/fstab and bkp/download?
– Rodrigo
Sep 28 '17 at 18:32
@Rodrigo I've edited my answer
– Gilles
Sep 28 '17 at 18:46
add a comment |
You can pass multiple source arguments.
rsync -a /etc/fstab /home/user/download bkp
This creates bkp/fstab and bkp/download, like the separate commands you gave. It may be desirable to preserve the source structure instead. To do this, use / as the source and use include-exclude rules to specify which files to copy. There are two ways to do this:
Explicitly include each file as well as each directory component leading to it, with
/***at the end of directories when you want to copy the whole directory tree:rsync -a
--include=/etc --include=/etc/fstab
--include=/home --include=/home/user --include='/home/user/download/***'
--exclude='*' / bkpInclude all top-level directories with
/*/(so that rsync will traverse/etcand/homewhen looking for files to copy) and second-level directories with/*/*/(for/home/user), but strip away directories in which no file gets copied. This is more convenient because you don't have to list parents explicitly. You could even use--prune-empty-dirs --include='*/'instead of counting the number of levels, but this is impractical here as rsync would traverse the whole filesystem to explore directories even though none of the include rules can match anything outside/etcand/home/user/download.rsync -a --prune-empty-dirs
--include='/*/' --include='/*/*/'
--include=/etc/fstab
--include='/home/user/download/***'
--exclude='*' / bkp
1
Great, but how to keep the directory structure inside bkp?
– Rodrigo
Sep 28 '17 at 18:23
I mean, bkp/etc/fstab and bkp/home/user/dowlonad? Or maybe /bkp/fstab and bkp/download?
– Rodrigo
Sep 28 '17 at 18:32
@Rodrigo I've edited my answer
– Gilles
Sep 28 '17 at 18:46
add a comment |
You can pass multiple source arguments.
rsync -a /etc/fstab /home/user/download bkp
This creates bkp/fstab and bkp/download, like the separate commands you gave. It may be desirable to preserve the source structure instead. To do this, use / as the source and use include-exclude rules to specify which files to copy. There are two ways to do this:
Explicitly include each file as well as each directory component leading to it, with
/***at the end of directories when you want to copy the whole directory tree:rsync -a
--include=/etc --include=/etc/fstab
--include=/home --include=/home/user --include='/home/user/download/***'
--exclude='*' / bkpInclude all top-level directories with
/*/(so that rsync will traverse/etcand/homewhen looking for files to copy) and second-level directories with/*/*/(for/home/user), but strip away directories in which no file gets copied. This is more convenient because you don't have to list parents explicitly. You could even use--prune-empty-dirs --include='*/'instead of counting the number of levels, but this is impractical here as rsync would traverse the whole filesystem to explore directories even though none of the include rules can match anything outside/etcand/home/user/download.rsync -a --prune-empty-dirs
--include='/*/' --include='/*/*/'
--include=/etc/fstab
--include='/home/user/download/***'
--exclude='*' / bkp
You can pass multiple source arguments.
rsync -a /etc/fstab /home/user/download bkp
This creates bkp/fstab and bkp/download, like the separate commands you gave. It may be desirable to preserve the source structure instead. To do this, use / as the source and use include-exclude rules to specify which files to copy. There are two ways to do this:
Explicitly include each file as well as each directory component leading to it, with
/***at the end of directories when you want to copy the whole directory tree:rsync -a
--include=/etc --include=/etc/fstab
--include=/home --include=/home/user --include='/home/user/download/***'
--exclude='*' / bkpInclude all top-level directories with
/*/(so that rsync will traverse/etcand/homewhen looking for files to copy) and second-level directories with/*/*/(for/home/user), but strip away directories in which no file gets copied. This is more convenient because you don't have to list parents explicitly. You could even use--prune-empty-dirs --include='*/'instead of counting the number of levels, but this is impractical here as rsync would traverse the whole filesystem to explore directories even though none of the include rules can match anything outside/etcand/home/user/download.rsync -a --prune-empty-dirs
--include='/*/' --include='/*/*/'
--include=/etc/fstab
--include='/home/user/download/***'
--exclude='*' / bkp
edited Sep 28 '17 at 18:46
answered May 30 '17 at 23:54
GillesGilles
536k12810821600
536k12810821600
1
Great, but how to keep the directory structure inside bkp?
– Rodrigo
Sep 28 '17 at 18:23
I mean, bkp/etc/fstab and bkp/home/user/dowlonad? Or maybe /bkp/fstab and bkp/download?
– Rodrigo
Sep 28 '17 at 18:32
@Rodrigo I've edited my answer
– Gilles
Sep 28 '17 at 18:46
add a comment |
1
Great, but how to keep the directory structure inside bkp?
– Rodrigo
Sep 28 '17 at 18:23
I mean, bkp/etc/fstab and bkp/home/user/dowlonad? Or maybe /bkp/fstab and bkp/download?
– Rodrigo
Sep 28 '17 at 18:32
@Rodrigo I've edited my answer
– Gilles
Sep 28 '17 at 18:46
1
1
Great, but how to keep the directory structure inside bkp?
– Rodrigo
Sep 28 '17 at 18:23
Great, but how to keep the directory structure inside bkp?
– Rodrigo
Sep 28 '17 at 18:23
I mean, bkp/etc/fstab and bkp/home/user/dowlonad? Or maybe /bkp/fstab and bkp/download?
– Rodrigo
Sep 28 '17 at 18:32
I mean, bkp/etc/fstab and bkp/home/user/dowlonad? Or maybe /bkp/fstab and bkp/download?
– Rodrigo
Sep 28 '17 at 18:32
@Rodrigo I've edited my answer
– Gilles
Sep 28 '17 at 18:46
@Rodrigo I've edited my answer
– Gilles
Sep 28 '17 at 18:46
add a comment |
I really like Gilles' answer, however, I'd like to add that in my view the requirement to sync multiple folders while preserving the directory structure is best met by passing multiple source arguments in conjunction with the --relative option.
In this case, we could have something as follows:
rsync -aR /etc/fstab /home/user/download bkp
which would result in bkp/etc/fstab and bkp/home/user/download.
The best part about this is that (I believe since rsync v. 2.6.7) we can in essence control how much of the directory structure we want to replicate at the receiver.
(See the documentation on the --relative option here)
So e.g. if we did this
rsync -aR /home/./user1/download /home/./user2/download bkp
we would end up with bkp/user1/download and bkp/user2/download.
add a comment |
I really like Gilles' answer, however, I'd like to add that in my view the requirement to sync multiple folders while preserving the directory structure is best met by passing multiple source arguments in conjunction with the --relative option.
In this case, we could have something as follows:
rsync -aR /etc/fstab /home/user/download bkp
which would result in bkp/etc/fstab and bkp/home/user/download.
The best part about this is that (I believe since rsync v. 2.6.7) we can in essence control how much of the directory structure we want to replicate at the receiver.
(See the documentation on the --relative option here)
So e.g. if we did this
rsync -aR /home/./user1/download /home/./user2/download bkp
we would end up with bkp/user1/download and bkp/user2/download.
add a comment |
I really like Gilles' answer, however, I'd like to add that in my view the requirement to sync multiple folders while preserving the directory structure is best met by passing multiple source arguments in conjunction with the --relative option.
In this case, we could have something as follows:
rsync -aR /etc/fstab /home/user/download bkp
which would result in bkp/etc/fstab and bkp/home/user/download.
The best part about this is that (I believe since rsync v. 2.6.7) we can in essence control how much of the directory structure we want to replicate at the receiver.
(See the documentation on the --relative option here)
So e.g. if we did this
rsync -aR /home/./user1/download /home/./user2/download bkp
we would end up with bkp/user1/download and bkp/user2/download.
I really like Gilles' answer, however, I'd like to add that in my view the requirement to sync multiple folders while preserving the directory structure is best met by passing multiple source arguments in conjunction with the --relative option.
In this case, we could have something as follows:
rsync -aR /etc/fstab /home/user/download bkp
which would result in bkp/etc/fstab and bkp/home/user/download.
The best part about this is that (I believe since rsync v. 2.6.7) we can in essence control how much of the directory structure we want to replicate at the receiver.
(See the documentation on the --relative option here)
So e.g. if we did this
rsync -aR /home/./user1/download /home/./user2/download bkp
we would end up with bkp/user1/download and bkp/user2/download.
answered Jan 23 at 10:46
ChristophChristoph
111
111
add a comment |
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%2f368210%2fhow-to-rsync-multiple-source-folders%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