{"id":422,"date":"2016-09-25T10:18:31","date_gmt":"2016-09-25T10:18:31","guid":{"rendered":"http:\/\/notnull.ro\/log\/?p=422"},"modified":"2020-09-25T06:08:29","modified_gmt":"2020-09-25T06:08:29","slug":"rsync-move-files-keeping-the-folders-structure","status":"publish","type":"post","link":"https:\/\/notnull.ro\/log\/rsync-move-files-keeping-the-folders-structure\/","title":{"rendered":"rsync move files keeping the folders structure"},"content":{"rendered":"<p>I&#8217;m just putting here this command to remember it next time when I need it.<\/p>\n<h3>Problem to be solved<\/h3>\n<p>When SD card of my photo camera is full I just upload the photos to my NAS server <a href=\"http:\/\/www.zyxel.com\/products_services\/nsa320s.shtml?t=p\">NSA320<\/a>\u00a0. After that usually I do some cleanup and one of the steps is to move the video (there are not only photos) \u00a0files from the the photo\/ directory to other location.<\/p>\n<p>Until now I did this step manually, to save time I was thinking to make it automatic.<\/p>\n<h3>Solution<\/h3>\n<p>This is what I want to do:<\/p>\n<ol>\n<li>Get shell access on my\u00a0<a href=\"http:\/\/www.zyxel.com\/products_services\/nsa320s.shtml?t=p\">NSA320<\/a>\u00a0, to do this I&#8217;ve installed <a href=\"https:\/\/nas-tweaks.net\/tutorials\/\">ffp (Fonz fun_plug)<\/a>. It is a collection of packages for\u00a0<a href=\"http:\/\/www.zyxel.com\/products_services\/nsa320s.shtml?t=p\">NSA320<\/a>\u00a0that includes a ssh server.<\/li>\n<li>After getting ssh access in step 1, I need to create a small scrip to move all the video files from $SOURCE_DIR to $DST_DIR. All video means files with next extensions:\n<ul>\n<li>.MOV (has to be no case sensitive)<\/li>\n<li>.MPG\/MP4\u00a0(has to be no case sensitive)<\/li>\n<li>.AVI (has to be no case sensitive)<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>I&#8217;m using <a href=\"https:\/\/linux.die.net\/man\/1\/rsync\">rsync <\/a>command.<\/p>\n<div><span style=\"color: #0000ff;\">rsync -rav &#8211;remove-source-files &#8211;exclude &#8216;*&#8217; &#8211;include &#8216;*\/&#8217; &#8211;include &#8216;*.[Mm][Oo][Vv]&#8217; &#8211;include &#8216;*.[Mm][pP][4gG]&#8217; &#8211;include &#8216;*.[Aa][Vv][Ii]&#8217; \u00a0&#8211;prune-empty-dirs\u00a0$SOURCE_DIR \u00a0$DST_DIR<\/span><\/div>\n<p>The meaning of\u00a0the arguments:<\/p>\n<ul>\n<li>-r = to go recursively on the entire $SOURCE_DIR<\/li>\n<li>-a = archive mode, it means to preserve most of the attributes of the files. For me important was last modified time<\/li>\n<li>-v = verbose; I just wanted to have a list with files that have been moved.<\/li>\n<li>&#8211;remove-source-files = to remove from source dir the files\u00a0that have been copied to destination.<\/li>\n<li>&#8211;exclude &#8216;*&#8217; = by default exclude all files; except the one passed to &#8220;&#8211;include&#8221; switches<\/li>\n<li>&#8211;include &#8216;*\/&#8217; = \u00a0include directories in teh list of files that have to be moved<\/li>\n<li>&#8211;include\u00a0&#8216;*.[Mm][Oo][Vv]&#8217; = include files with .MOV extension; no case sensitive. Similar for .MPG, .MP4, .AVI<\/li>\n<li>&#8211;prune-empty-dirs = do not copy empty dirs from source to destination<\/li>\n<\/ul>\n<p>At the end of the command you will noticed something like this:<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #0000ff;\">sent 24287985339 bytes received 8458 bytes 12766356.79 bytes\/sec<\/span><br \/>\n<span style=\"color: #0000ff;\"> total size is 24511383985 speedup is 1.01<\/span><\/p>\n<p>On my\u00a0<a href=\"http:\/\/www.zyxel.com\/products_services\/nsa320s.shtml?t=p\">NSA320<\/a>\u00a0it took few minutes to move ~23GB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m just putting here this command to remember it next time when I need it. Problem to be solved When SD card of my photo camera is full I just upload the photos to my NAS server NSA320\u00a0. After that usually I do some cleanup and one of the steps is to move the video <a href='https:\/\/notnull.ro\/log\/rsync-move-files-keeping-the-folders-structure\/' class='excerpt-more'>&#8230; Read Full Article<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,7],"tags":[],"class_list":["post-422","post","type-post","status-publish","format-standard","hentry","category-shells","category-unix","category-17-id","category-7-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/posts\/422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/comments?post=422"}],"version-history":[{"count":11,"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/posts\/422\/revisions"}],"predecessor-version":[{"id":626,"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/posts\/422\/revisions\/626"}],"wp:attachment":[{"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/media?parent=422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/categories?post=422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notnull.ro\/log\/wp-json\/wp\/v2\/tags?post=422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}