Rsync: How do I sync only certain filetypes from certain directories?












2














I want to copy all image type files from a few directories to /images.
I want to copy all video type files from the same directories to /videos.
I want to exclude all dot directories and dot files (hidden files and directories).



Directory structure:



DCIM (GOOD)
DCIM/.thumbnails (BAD)
DCIM/AccessoryCamera (GOOD)
.cloudagent (BAD)
Pictures (GOOD)
Downloads (GOOD)


I am trying:



rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'

rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.mov" --include "*.mpeg" --include "*.mpg" --include "*.mp4" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/videos'









share|improve this question




















  • 2




    Can you give more information on what is not working as expected?
    – Bruno9779
    Jun 2 '17 at 18:09










  • Why are you doubly quoting '"*"' and so on? This should just be '*'.
    – meuh
    Jun 3 '17 at 19:22
















2














I want to copy all image type files from a few directories to /images.
I want to copy all video type files from the same directories to /videos.
I want to exclude all dot directories and dot files (hidden files and directories).



Directory structure:



DCIM (GOOD)
DCIM/.thumbnails (BAD)
DCIM/AccessoryCamera (GOOD)
.cloudagent (BAD)
Pictures (GOOD)
Downloads (GOOD)


I am trying:



rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'

rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.mov" --include "*.mpeg" --include "*.mpg" --include "*.mp4" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/videos'









share|improve this question




















  • 2




    Can you give more information on what is not working as expected?
    – Bruno9779
    Jun 2 '17 at 18:09










  • Why are you doubly quoting '"*"' and so on? This should just be '*'.
    – meuh
    Jun 3 '17 at 19:22














2












2








2







I want to copy all image type files from a few directories to /images.
I want to copy all video type files from the same directories to /videos.
I want to exclude all dot directories and dot files (hidden files and directories).



Directory structure:



DCIM (GOOD)
DCIM/.thumbnails (BAD)
DCIM/AccessoryCamera (GOOD)
.cloudagent (BAD)
Pictures (GOOD)
Downloads (GOOD)


I am trying:



rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'

rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.mov" --include "*.mpeg" --include "*.mpg" --include "*.mp4" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/videos'









share|improve this question















I want to copy all image type files from a few directories to /images.
I want to copy all video type files from the same directories to /videos.
I want to exclude all dot directories and dot files (hidden files and directories).



Directory structure:



DCIM (GOOD)
DCIM/.thumbnails (BAD)
DCIM/AccessoryCamera (GOOD)
.cloudagent (BAD)
Pictures (GOOD)
Downloads (GOOD)


I am trying:



rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'

rsync -ravtz --progress --prune-empty-dirs --include "DCIM/" --include "Download/*" --include "Picture/" --include "*.mov" --include "*.mpeg" --include "*.mpg" --include "*.mp4" --exclude '"*"' --exclude '".*"' --exclude '"*/"' --exclude '".*/"' --exclude '"DCIM/.thumbnails/*' --log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/videos'






rsync






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 2 '17 at 18:26









Bruno9779

1,128515




1,128515










asked Jun 2 '17 at 17:55









Rob Campbell

111




111








  • 2




    Can you give more information on what is not working as expected?
    – Bruno9779
    Jun 2 '17 at 18:09










  • Why are you doubly quoting '"*"' and so on? This should just be '*'.
    – meuh
    Jun 3 '17 at 19:22














  • 2




    Can you give more information on what is not working as expected?
    – Bruno9779
    Jun 2 '17 at 18:09










  • Why are you doubly quoting '"*"' and so on? This should just be '*'.
    – meuh
    Jun 3 '17 at 19:22








2




2




Can you give more information on what is not working as expected?
– Bruno9779
Jun 2 '17 at 18:09




Can you give more information on what is not working as expected?
– Bruno9779
Jun 2 '17 at 18:09












Why are you doubly quoting '"*"' and so on? This should just be '*'.
– meuh
Jun 3 '17 at 19:22




Why are you doubly quoting '"*"' and so on? This should just be '*'.
– meuh
Jun 3 '17 at 19:22










2 Answers
2






active

oldest

votes


















3














See Rsync filter: copying one pattern only for more explanations on how to build an rsync filter. The general idea is to include what you need (including any directories leading to what you need) and exclude the rest at the end.



rsync -az --progress --prune-empty-dirs 
--exclude '.*'
--include "/DCIM" --include "/Download" --include "/Picture" --exclude '/*'
--include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef"
--include '*/' --exclude '*'
--log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'



  1. Exclude all dot files.

  2. Include some directories and exclude everything else at the top level.

  3. Include the file types you want.

  4. Include all directories (except the ones already excluded at the top level) and exclude everything else.






share|improve this answer





















  • This is still including all files. .mp4 files are being backed up with this command for some reason.
    – Rob Campbell
    Jun 5 '17 at 11:40



















1














(1) Create a text file that houses the directories that you want to synchronize from your device:



./input_dirs



Contents of ./input_dirs:




./DCIM
./Pictures
./DCIM/AccessoryCamera
./Downloads



Use the --files-from=./input_dirs.txt param to load the directories in question into RSYNC



(2) Leverage the --filter='dir-merge ./filter_file' param to load the extension filters that you want. (eg: *.png *.gif *.jpg)



Contents of ./filter_file:




+ *.png
+ *.jpg
+ *.gif
- /*



(3) I just ran this as a test on a Linux Sandbox server and it worked. Note that the only files that should be copied are .png, .gif, *.jpg :



Results:




[root@localhost ~]# ls -Fal
total 1012
dr-xr-x---. 4 root root 4096 Jun 5 20:03 ./
dr-xr-xr-x. 26 root root 4096 May 30 15:16 ../
-rw-------. 1 root root 1219 May 30 15:04 anaconda-ks.cfg
-rw-------. 1 root root 7161 Jun 5 19:45 .bash_history
-rw-r--r--. 1 root root 18 Apr 29 2010 .bash_logout
-rw-r--r--. 1 root root 176 Apr 29 2010 .bash_profile
-rw-r--r--. 1 root root 176 Apr 29 2010 .bashrc
-rw-r--r--. 1 root root 100 Apr 29 2010 .cshrc
-rwxr--r--. 1 root root 9565 May 30 20:41 cve.sh*
drwxr-xr-x. 2 root root 4096 Jun 5 20:03 dest/
-rw-r--r--. 1 root root 14704 Dec 27 12:40 epel-release-7-9.noarch.rpm
-rw-r--r--. 1 root root 508 May 30 22:08 file1
-rw-r--r--. 1 root root 508 May 30 22:08 file2
-rw-r--r--. 1 root root 29 Jun 5 20:03 filter_file
-rw-r--r--. 1 root root 3 Jun 5 19:46 input_dirs
-rw-r--r--. 1 root root 28978 May 30 15:04 install.log
-rw-r--r--. 1 root root 7572 May 30 15:01 install.log.syslog
-rw-------. 1 root root 88 Jun 4 17:49 .lesshst
drwxr-----. 3 root root 4096 Jun 4 17:45 .pki/
-rw-r--r--. 1 root root 624068 May 24 04:34 samba-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 266168 May 24 04:34 samba-libs-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 129 Apr 29 2010 .tcshrc
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.gif
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.jpg
-rw-r--r--. 1 root root 0 Jun 5 19:54 test.png




[root@localhost ~]# rsync -av --dry-run --files-from=./input_dirs --filter='dir-merge ./filter_file' ./ ./dest


building file list ... done


./


test.gif
test.jpg
test.png


sent 92 bytes received 24 bytes 232.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)



Remove --dry-run to actually copy files.






share|improve this answer























  • This doesn't work either.
    – Rob Campbell
    Jun 5 '17 at 22:14










  • I'm getting (DRY RUN) even though there is no --dry-run option being used.
    – Rob Campbell
    Jun 12 '17 at 2:21












  • @RobCampbell That behaviour I can't explain. :-/
    – AfroJoe
    Jun 12 '17 at 13:05











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%2f368857%2frsync-how-do-i-sync-only-certain-filetypes-from-certain-directories%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









3














See Rsync filter: copying one pattern only for more explanations on how to build an rsync filter. The general idea is to include what you need (including any directories leading to what you need) and exclude the rest at the end.



rsync -az --progress --prune-empty-dirs 
--exclude '.*'
--include "/DCIM" --include "/Download" --include "/Picture" --exclude '/*'
--include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef"
--include '*/' --exclude '*'
--log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'



  1. Exclude all dot files.

  2. Include some directories and exclude everything else at the top level.

  3. Include the file types you want.

  4. Include all directories (except the ones already excluded at the top level) and exclude everything else.






share|improve this answer





















  • This is still including all files. .mp4 files are being backed up with this command for some reason.
    – Rob Campbell
    Jun 5 '17 at 11:40
















3














See Rsync filter: copying one pattern only for more explanations on how to build an rsync filter. The general idea is to include what you need (including any directories leading to what you need) and exclude the rest at the end.



rsync -az --progress --prune-empty-dirs 
--exclude '.*'
--include "/DCIM" --include "/Download" --include "/Picture" --exclude '/*'
--include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef"
--include '*/' --exclude '*'
--log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'



  1. Exclude all dot files.

  2. Include some directories and exclude everything else at the top level.

  3. Include the file types you want.

  4. Include all directories (except the ones already excluded at the top level) and exclude everything else.






share|improve this answer





















  • This is still including all files. .mp4 files are being backed up with this command for some reason.
    – Rob Campbell
    Jun 5 '17 at 11:40














3












3








3






See Rsync filter: copying one pattern only for more explanations on how to build an rsync filter. The general idea is to include what you need (including any directories leading to what you need) and exclude the rest at the end.



rsync -az --progress --prune-empty-dirs 
--exclude '.*'
--include "/DCIM" --include "/Download" --include "/Picture" --exclude '/*'
--include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef"
--include '*/' --exclude '*'
--log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'



  1. Exclude all dot files.

  2. Include some directories and exclude everything else at the top level.

  3. Include the file types you want.

  4. Include all directories (except the ones already excluded at the top level) and exclude everything else.






share|improve this answer












See Rsync filter: copying one pattern only for more explanations on how to build an rsync filter. The general idea is to include what you need (including any directories leading to what you need) and exclude the rest at the end.



rsync -az --progress --prune-empty-dirs 
--exclude '.*'
--include "/DCIM" --include "/Download" --include "/Picture" --exclude '/*'
--include "*.jpg" --include "*.png" --include "*.gif" --include "*.nef"
--include '*/' --exclude '*'
--log-file=/mm/rsync.log /mnt/S8/sdcard/ '/mm/images'



  1. Exclude all dot files.

  2. Include some directories and exclude everything else at the top level.

  3. Include the file types you want.

  4. Include all directories (except the ones already excluded at the top level) and exclude everything else.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 4 '17 at 0:30









Gilles

527k12810561581




527k12810561581












  • This is still including all files. .mp4 files are being backed up with this command for some reason.
    – Rob Campbell
    Jun 5 '17 at 11:40


















  • This is still including all files. .mp4 files are being backed up with this command for some reason.
    – Rob Campbell
    Jun 5 '17 at 11:40
















This is still including all files. .mp4 files are being backed up with this command for some reason.
– Rob Campbell
Jun 5 '17 at 11:40




This is still including all files. .mp4 files are being backed up with this command for some reason.
– Rob Campbell
Jun 5 '17 at 11:40













1














(1) Create a text file that houses the directories that you want to synchronize from your device:



./input_dirs



Contents of ./input_dirs:




./DCIM
./Pictures
./DCIM/AccessoryCamera
./Downloads



Use the --files-from=./input_dirs.txt param to load the directories in question into RSYNC



(2) Leverage the --filter='dir-merge ./filter_file' param to load the extension filters that you want. (eg: *.png *.gif *.jpg)



Contents of ./filter_file:




+ *.png
+ *.jpg
+ *.gif
- /*



(3) I just ran this as a test on a Linux Sandbox server and it worked. Note that the only files that should be copied are .png, .gif, *.jpg :



Results:




[root@localhost ~]# ls -Fal
total 1012
dr-xr-x---. 4 root root 4096 Jun 5 20:03 ./
dr-xr-xr-x. 26 root root 4096 May 30 15:16 ../
-rw-------. 1 root root 1219 May 30 15:04 anaconda-ks.cfg
-rw-------. 1 root root 7161 Jun 5 19:45 .bash_history
-rw-r--r--. 1 root root 18 Apr 29 2010 .bash_logout
-rw-r--r--. 1 root root 176 Apr 29 2010 .bash_profile
-rw-r--r--. 1 root root 176 Apr 29 2010 .bashrc
-rw-r--r--. 1 root root 100 Apr 29 2010 .cshrc
-rwxr--r--. 1 root root 9565 May 30 20:41 cve.sh*
drwxr-xr-x. 2 root root 4096 Jun 5 20:03 dest/
-rw-r--r--. 1 root root 14704 Dec 27 12:40 epel-release-7-9.noarch.rpm
-rw-r--r--. 1 root root 508 May 30 22:08 file1
-rw-r--r--. 1 root root 508 May 30 22:08 file2
-rw-r--r--. 1 root root 29 Jun 5 20:03 filter_file
-rw-r--r--. 1 root root 3 Jun 5 19:46 input_dirs
-rw-r--r--. 1 root root 28978 May 30 15:04 install.log
-rw-r--r--. 1 root root 7572 May 30 15:01 install.log.syslog
-rw-------. 1 root root 88 Jun 4 17:49 .lesshst
drwxr-----. 3 root root 4096 Jun 4 17:45 .pki/
-rw-r--r--. 1 root root 624068 May 24 04:34 samba-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 266168 May 24 04:34 samba-libs-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 129 Apr 29 2010 .tcshrc
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.gif
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.jpg
-rw-r--r--. 1 root root 0 Jun 5 19:54 test.png




[root@localhost ~]# rsync -av --dry-run --files-from=./input_dirs --filter='dir-merge ./filter_file' ./ ./dest


building file list ... done


./


test.gif
test.jpg
test.png


sent 92 bytes received 24 bytes 232.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)



Remove --dry-run to actually copy files.






share|improve this answer























  • This doesn't work either.
    – Rob Campbell
    Jun 5 '17 at 22:14










  • I'm getting (DRY RUN) even though there is no --dry-run option being used.
    – Rob Campbell
    Jun 12 '17 at 2:21












  • @RobCampbell That behaviour I can't explain. :-/
    – AfroJoe
    Jun 12 '17 at 13:05
















1














(1) Create a text file that houses the directories that you want to synchronize from your device:



./input_dirs



Contents of ./input_dirs:




./DCIM
./Pictures
./DCIM/AccessoryCamera
./Downloads



Use the --files-from=./input_dirs.txt param to load the directories in question into RSYNC



(2) Leverage the --filter='dir-merge ./filter_file' param to load the extension filters that you want. (eg: *.png *.gif *.jpg)



Contents of ./filter_file:




+ *.png
+ *.jpg
+ *.gif
- /*



(3) I just ran this as a test on a Linux Sandbox server and it worked. Note that the only files that should be copied are .png, .gif, *.jpg :



Results:




[root@localhost ~]# ls -Fal
total 1012
dr-xr-x---. 4 root root 4096 Jun 5 20:03 ./
dr-xr-xr-x. 26 root root 4096 May 30 15:16 ../
-rw-------. 1 root root 1219 May 30 15:04 anaconda-ks.cfg
-rw-------. 1 root root 7161 Jun 5 19:45 .bash_history
-rw-r--r--. 1 root root 18 Apr 29 2010 .bash_logout
-rw-r--r--. 1 root root 176 Apr 29 2010 .bash_profile
-rw-r--r--. 1 root root 176 Apr 29 2010 .bashrc
-rw-r--r--. 1 root root 100 Apr 29 2010 .cshrc
-rwxr--r--. 1 root root 9565 May 30 20:41 cve.sh*
drwxr-xr-x. 2 root root 4096 Jun 5 20:03 dest/
-rw-r--r--. 1 root root 14704 Dec 27 12:40 epel-release-7-9.noarch.rpm
-rw-r--r--. 1 root root 508 May 30 22:08 file1
-rw-r--r--. 1 root root 508 May 30 22:08 file2
-rw-r--r--. 1 root root 29 Jun 5 20:03 filter_file
-rw-r--r--. 1 root root 3 Jun 5 19:46 input_dirs
-rw-r--r--. 1 root root 28978 May 30 15:04 install.log
-rw-r--r--. 1 root root 7572 May 30 15:01 install.log.syslog
-rw-------. 1 root root 88 Jun 4 17:49 .lesshst
drwxr-----. 3 root root 4096 Jun 4 17:45 .pki/
-rw-r--r--. 1 root root 624068 May 24 04:34 samba-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 266168 May 24 04:34 samba-libs-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 129 Apr 29 2010 .tcshrc
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.gif
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.jpg
-rw-r--r--. 1 root root 0 Jun 5 19:54 test.png




[root@localhost ~]# rsync -av --dry-run --files-from=./input_dirs --filter='dir-merge ./filter_file' ./ ./dest


building file list ... done


./


test.gif
test.jpg
test.png


sent 92 bytes received 24 bytes 232.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)



Remove --dry-run to actually copy files.






share|improve this answer























  • This doesn't work either.
    – Rob Campbell
    Jun 5 '17 at 22:14










  • I'm getting (DRY RUN) even though there is no --dry-run option being used.
    – Rob Campbell
    Jun 12 '17 at 2:21












  • @RobCampbell That behaviour I can't explain. :-/
    – AfroJoe
    Jun 12 '17 at 13:05














1












1








1






(1) Create a text file that houses the directories that you want to synchronize from your device:



./input_dirs



Contents of ./input_dirs:




./DCIM
./Pictures
./DCIM/AccessoryCamera
./Downloads



Use the --files-from=./input_dirs.txt param to load the directories in question into RSYNC



(2) Leverage the --filter='dir-merge ./filter_file' param to load the extension filters that you want. (eg: *.png *.gif *.jpg)



Contents of ./filter_file:




+ *.png
+ *.jpg
+ *.gif
- /*



(3) I just ran this as a test on a Linux Sandbox server and it worked. Note that the only files that should be copied are .png, .gif, *.jpg :



Results:




[root@localhost ~]# ls -Fal
total 1012
dr-xr-x---. 4 root root 4096 Jun 5 20:03 ./
dr-xr-xr-x. 26 root root 4096 May 30 15:16 ../
-rw-------. 1 root root 1219 May 30 15:04 anaconda-ks.cfg
-rw-------. 1 root root 7161 Jun 5 19:45 .bash_history
-rw-r--r--. 1 root root 18 Apr 29 2010 .bash_logout
-rw-r--r--. 1 root root 176 Apr 29 2010 .bash_profile
-rw-r--r--. 1 root root 176 Apr 29 2010 .bashrc
-rw-r--r--. 1 root root 100 Apr 29 2010 .cshrc
-rwxr--r--. 1 root root 9565 May 30 20:41 cve.sh*
drwxr-xr-x. 2 root root 4096 Jun 5 20:03 dest/
-rw-r--r--. 1 root root 14704 Dec 27 12:40 epel-release-7-9.noarch.rpm
-rw-r--r--. 1 root root 508 May 30 22:08 file1
-rw-r--r--. 1 root root 508 May 30 22:08 file2
-rw-r--r--. 1 root root 29 Jun 5 20:03 filter_file
-rw-r--r--. 1 root root 3 Jun 5 19:46 input_dirs
-rw-r--r--. 1 root root 28978 May 30 15:04 install.log
-rw-r--r--. 1 root root 7572 May 30 15:01 install.log.syslog
-rw-------. 1 root root 88 Jun 4 17:49 .lesshst
drwxr-----. 3 root root 4096 Jun 4 17:45 .pki/
-rw-r--r--. 1 root root 624068 May 24 04:34 samba-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 266168 May 24 04:34 samba-libs-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 129 Apr 29 2010 .tcshrc
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.gif
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.jpg
-rw-r--r--. 1 root root 0 Jun 5 19:54 test.png




[root@localhost ~]# rsync -av --dry-run --files-from=./input_dirs --filter='dir-merge ./filter_file' ./ ./dest


building file list ... done


./


test.gif
test.jpg
test.png


sent 92 bytes received 24 bytes 232.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)



Remove --dry-run to actually copy files.






share|improve this answer














(1) Create a text file that houses the directories that you want to synchronize from your device:



./input_dirs



Contents of ./input_dirs:




./DCIM
./Pictures
./DCIM/AccessoryCamera
./Downloads



Use the --files-from=./input_dirs.txt param to load the directories in question into RSYNC



(2) Leverage the --filter='dir-merge ./filter_file' param to load the extension filters that you want. (eg: *.png *.gif *.jpg)



Contents of ./filter_file:




+ *.png
+ *.jpg
+ *.gif
- /*



(3) I just ran this as a test on a Linux Sandbox server and it worked. Note that the only files that should be copied are .png, .gif, *.jpg :



Results:




[root@localhost ~]# ls -Fal
total 1012
dr-xr-x---. 4 root root 4096 Jun 5 20:03 ./
dr-xr-xr-x. 26 root root 4096 May 30 15:16 ../
-rw-------. 1 root root 1219 May 30 15:04 anaconda-ks.cfg
-rw-------. 1 root root 7161 Jun 5 19:45 .bash_history
-rw-r--r--. 1 root root 18 Apr 29 2010 .bash_logout
-rw-r--r--. 1 root root 176 Apr 29 2010 .bash_profile
-rw-r--r--. 1 root root 176 Apr 29 2010 .bashrc
-rw-r--r--. 1 root root 100 Apr 29 2010 .cshrc
-rwxr--r--. 1 root root 9565 May 30 20:41 cve.sh*
drwxr-xr-x. 2 root root 4096 Jun 5 20:03 dest/
-rw-r--r--. 1 root root 14704 Dec 27 12:40 epel-release-7-9.noarch.rpm
-rw-r--r--. 1 root root 508 May 30 22:08 file1
-rw-r--r--. 1 root root 508 May 30 22:08 file2
-rw-r--r--. 1 root root 29 Jun 5 20:03 filter_file
-rw-r--r--. 1 root root 3 Jun 5 19:46 input_dirs
-rw-r--r--. 1 root root 28978 May 30 15:04 install.log
-rw-r--r--. 1 root root 7572 May 30 15:01 install.log.syslog
-rw-------. 1 root root 88 Jun 4 17:49 .lesshst
drwxr-----. 3 root root 4096 Jun 4 17:45 .pki/
-rw-r--r--. 1 root root 624068 May 24 04:34 samba-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 266168 May 24 04:34 samba-libs-4.4.4-14.el7_3.x86_64.rpm
-rw-r--r--. 1 root root 129 Apr 29 2010 .tcshrc
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.gif
-rw-r--r--. 1 root root 0 Jun 5 19:55 test.jpg
-rw-r--r--. 1 root root 0 Jun 5 19:54 test.png




[root@localhost ~]# rsync -av --dry-run --files-from=./input_dirs --filter='dir-merge ./filter_file' ./ ./dest


building file list ... done


./


test.gif
test.jpg
test.png


sent 92 bytes received 24 bytes 232.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)



Remove --dry-run to actually copy files.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 15 at 22:19









Rui F Ribeiro

38.9k1479129




38.9k1479129










answered Jun 2 '17 at 20:02









AfroJoe

42518




42518












  • This doesn't work either.
    – Rob Campbell
    Jun 5 '17 at 22:14










  • I'm getting (DRY RUN) even though there is no --dry-run option being used.
    – Rob Campbell
    Jun 12 '17 at 2:21












  • @RobCampbell That behaviour I can't explain. :-/
    – AfroJoe
    Jun 12 '17 at 13:05


















  • This doesn't work either.
    – Rob Campbell
    Jun 5 '17 at 22:14










  • I'm getting (DRY RUN) even though there is no --dry-run option being used.
    – Rob Campbell
    Jun 12 '17 at 2:21












  • @RobCampbell That behaviour I can't explain. :-/
    – AfroJoe
    Jun 12 '17 at 13:05
















This doesn't work either.
– Rob Campbell
Jun 5 '17 at 22:14




This doesn't work either.
– Rob Campbell
Jun 5 '17 at 22:14












I'm getting (DRY RUN) even though there is no --dry-run option being used.
– Rob Campbell
Jun 12 '17 at 2:21






I'm getting (DRY RUN) even though there is no --dry-run option being used.
– Rob Campbell
Jun 12 '17 at 2:21














@RobCampbell That behaviour I can't explain. :-/
– AfroJoe
Jun 12 '17 at 13:05




@RobCampbell That behaviour I can't explain. :-/
– AfroJoe
Jun 12 '17 at 13:05


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f368857%2frsync-how-do-i-sync-only-certain-filetypes-from-certain-directories%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

Morgemoulin

Scott Moir

Souastre