Sep 252016
 

I’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 . After that usually I do some cleanup and one of the steps is to move the video (there are not only photos)  files from the the photo/ directory to other location.

Until now I did this step manually, to save time I was thinking to make it automatic.

Solution

This is what I want to do:

  1. Get shell access on my NSA320 , to do this I’ve installed ffp (Fonz fun_plug). It is a collection of packages for NSA320 that includes a ssh server.
  2. 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:
    • .MOV (has to be no case sensitive)
    • .MPG/MP4 (has to be no case sensitive)
    • .AVI (has to be no case sensitive)

I’m using rsync command.

rsync -rav –remove-source-files –exclude ‘*’ –include ‘*/’ –include ‘*.[Mm][Oo][Vv]’ –include ‘*.[Mm][pP][4gG]’ –include ‘*.[Aa][Vv][Ii]’  –prune-empty-dirs $SOURCE_DIR  $DST_DIR

The meaning of the arguments:

  • -r = to go recursively on the entire $SOURCE_DIR
  • -a = archive mode, it means to preserve most of the attributes of the files. For me important was last modified time
  • -v = verbose; I just wanted to have a list with files that have been moved.
  • –remove-source-files = to remove from source dir the files that have been copied to destination.
  • –exclude ‘*’ = by default exclude all files; except the one passed to “–include” switches
  • –include ‘*/’ =  include directories in teh list of files that have to be moved
  • –include ‘*.[Mm][Oo][Vv]’ = include files with .MOV extension; no case sensitive. Similar for .MPG, .MP4, .AVI
  • –prune-empty-dirs = do not copy empty dirs from source to destination

At the end of the command you will noticed something like this:

sent 24287985339 bytes received 8458 bytes 12766356.79 bytes/sec
total size is 24511383985 speedup is 1.01

On my NSA320 it took few minutes to move ~23GB.

 Posted by at 10:18 AM

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)