0

Some command line syntax I don't know how to set, am a noob sometimes, sorry is that's obvious

Let's says I have the following path for all my assets :

/var/www/site/system/images/{image_id}/{format}/{file}.{extension}

Inside the {image_id} folder, I have multiple formats (original, medium, thumb, etc...).

I only want to import the /var/www/site/system/images/{image_id}/original folder, and keep the structure locally

scp -r username@server:/var/www/site/system/images/*/original ~/Site/site/system/images

This one does get it all, but all the files end up in the same and unique folder, no structure.

I'd like to keep the structure. Is there something to do for it ?

Ben
  • 113
  • 1
  • 9
  • 1
    You can use rsync and exclude medium and thumb –  Oct 13 '12 at 11:31
  • Thx Eric, you put me on the way; exclude was the thing. Always end up on some [slicehost's](http://articles.slicehost.com/2007/10/10/rsync-exclude-files-and-folders) clean explanations in the end – Ben Oct 13 '12 at 21:10

1 Answers1

4

Use rsync, becasue scp is limited in many ways.

To get you started here is an example:

rsync genja.org:/home/www/*/html/ /tmp/dest/html/ -avin 
host: genja.lan 
receiving incremental file list
created directory /tmp/dest/html
cd+++++++++ ./
>f+++++++++ tabs.html
cd+++++++++ borders/
cd+++++++++ borders/border-radius/
>f+++++++++ borders/border-radius/border-radius.htc
>f+++++++++ borders/border-radius/border-radius.html
cd+++++++++ borders/css-tricks.com/
(...)

The important options are -a and -v if you want to see what is going on. If you add -in then the command will only pretend that it is running, so you can review what will get copied and where.

There is a subtle difference in how trailing slashed are treated. Just make sure you include a trailing slash on both the destination and the source folders to begin with.

  • The structure is not maintained in that case, a last in my case; all the files get downloaded in the same folder – Ben Oct 13 '12 at 21:13
  • Then you need to copy from a higher level folder and use --exclude for what you don't need. – Ярослав Рахматуллин Oct 13 '12 at 21:31
  • --exclude was the thing – Ben Oct 13 '12 at 21:42
  • Okay, I'm not sure to open a new question for this. But I see you there. I need to know what has just been synced in order to process the files just received each time. How can I cleanly save the rsync output somewhere ? – Ben Oct 13 '12 at 21:46
  • I have never used this options, but there is --log-file=FILE for rsync which can be customized. You can look into that. .....The simple thing to do would be: rsync /source /destination -av 2>&1 > /tmp/rsync-out.txt . This will save all the output and errors into /tmp/rsync-out.txt – Ярослав Рахматуллин Oct 13 '12 at 21:51
  • THX! I'll look for this. Just wondering and not aware enough about other solutions, my point is to 'sync and process'; is there a more efficient way to do it better (some other tool) ? – Ben Oct 13 '12 at 21:59
  • rsync is pretty much the best there is, once you get used to it. I would suggest something better if I knew anything better ;) – Ярослав Рахматуллин Oct 13 '12 at 22:21
  • Aight, I'll look deeper into, that will do the thing I guess – Ben Oct 14 '12 at 13:40