{"id":174,"date":"2013-02-26T10:43:39","date_gmt":"2013-02-26T10:43:39","guid":{"rendered":"http:\/\/www.nicovs.be\/?p=174"},"modified":"2014-02-27T12:28:33","modified_gmt":"2014-02-27T12:28:33","slug":"rsync-files-younger-or-older-than","status":"publish","type":"post","link":"https:\/\/www.nicovs.be\/?p=174","title":{"rendered":"Rsync files younger or older than"},"content":{"rendered":"<p>Today I needed to copy all files from a certain folder, but younger than 1 month \u00a0to a remote machine.<\/p>\n<p>I knew how to use find of course&#8230; and rsync is pretty easy too&#8230; Combining these 2 needs some explanation:<\/p>\n<p>Finding files younger than 31 days is performed like this:<\/p>\n<pre class=\"lang:default decode:true\">find \/path\/to\/folder -type f -mtime -31<\/pre>\n<p>Rsyncing all files from a folder is pretty easy too:<\/p>\n<pre class=\"lang:default decode:true\">rsync -avhR \/path\/to\/folder\/* user@remote_ip:\/path\/to\/destination\/folder<\/pre>\n<p>Now, if you would like to rsync only the filers younger thn 31 days from your source folder, you can combine rsync and find in this way:<\/p>\n<pre class=\"lang:default decode:true\">rsync -Ravh `find \/path\/to\/folder\/ -type f -mtime -31`  user@remote_ip:\/path\/to\/destination\/folder<\/pre>\n<p>However&#8230; this is not 100 working as intended&#8230; This will skip filename with spaces, as the space are not escaped during the rsync&#8230;<\/p>\n<p>The solution for this is to split the one liner above into 2 seperate commands again:<\/p>\n<p>1) perform the find, and write the output to a tempfile:<\/p>\n<pre class=\"lang:default decode:true\">find \/path\/to\/folder -type f -mtime -31 &gt; \/tmp\/rsyncfiles<\/pre>\n<p>2) perform the rsync with the &#8211;from-files parameter:<\/p>\n<p>(do not forget the . in the command to declare a &#8216;source dir&#8217;)<\/p>\n<pre>rsync -Ravh --files-from=\/tmp\/rsyncfiles \/ user@remote_ip:\/path\/to\/destination\/folder<\/pre>\n<p><span style=\"text-decoration: underline;\">Remark<\/span>: When using relative paths, you could\/should change the \/path\/to\/folder to path\/to\/folder and put a . instead of a \/ in your rsync command<br \/>\nE.g. like this:<\/p>\n<pre class=\"lang:sh decode:true\">cd \/var\r\nfind . -mtime -6 &gt; \/tmp\/rsyncfiles\r\nrsync -Ravh --files-from=\/tmp\/rsyncfiles . root@www.someserver.com:\/root\/backup --dry-run\r\nbuilding file list ... done\r\n.\/\r\nlocatedb.n\r\ncache\/\r\ncron\/\r\nempty\/\r\nlib\/\r\nlog\/\r\nlog\/setup.log\r\nlog\/setup.log.full\r\nrun\/\r\nrun\/utmp\r\ntmp\/\r\n\r\nsent 372 bytes  received 48 bytes  280.00 bytes\/sec<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today I needed to copy all files from a certain folder, but younger than 1 month \u00a0to a remote machine. I knew how to use find of course&#8230; and rsync is pretty easy too&#8230; Combining these 2 needs some explanation: Finding files younger than 31 days is performed like this: find \/path\/to\/folder -type f -mtime [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[20,4,6],"tags":[37,35,36,34],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-centos","category-debian","category-ubuntu","tag-copy","tag-find","tag-mtime","tag-rsync"],"_links":{"self":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174"}],"version-history":[{"count":5,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}