# Help with rsync

**URL:** <https://boards.straightdope.com/t/help-with-rsync/728628>\
**Category:** Factual Questions\
**Created:** [August 23, 2015, 6:56pm UTC](https://boards.straightdope.com/t/help-with-rsync/728628 "2015-08-23T18:56:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaelghat](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aaelghat](https://boards.straightdope.com/u/aaelghat)\
**Post date:** [August 23, 2015, 6:56pm UTC](https://boards.straightdope.com/t/help-with-rsync/728628/1 "2015-08-23T18:56:34Z")

</div>

Hi there…

Let’s say I have a set of directories in server A like this:

/var/spool/tv/files/default/00001/INBOX  
/var/spool/tv/files/default/00002/INBOX  
/var/spool/tv/files/default/00003/INBOX  
/var/spool/tv/files/default/00004/INBOX

The numbers 00001, etc. are account numbers, and I want to copy the files in the directories above to a second server using the structure below (the directories don’t exist).

/home/table/public\_html/backpack/wp-content/uploads/production/orders/00001  
/home/table/public\_html/backpack/wp-content/uploads/production/orders/00002  
/home/table/public\_html/backpack/wp-content/uploads/production/orders/00003  
/home/table/public\_html/backpack/wp-content/uploads/production/orders/00004

So for server A, the account number 00001 is identified by the second to last folder (before INBOX) and I want to create a folder on the second server that has the account number after the orders directory.

How would I do that using rsync? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [August 23, 2015, 10:15pm UTC](https://boards.straightdope.com/t/help-with-rsync/728628/2 "2015-08-23T22:15:42Z")

</div>

I don’t think you can do that with rsync, but you can use whatever scripting language is on that system to manipulate the files before or after you copy them. For example, rsync -Phav default/ orders/. That will recursively copy everything from default to orders, and you’ll have 00001, 00002, etc. Then use the scripting language to go through all of those, move everything in INBOX up one level, and delete the INBOX folder.

---

<div class="post-metadata">

**Author:** ![Isilder](https://avatars.discourse-cdn.com/v4/letter/i/cc9497/32.png) [@Isilder](https://boards.straightdope.com/u/Isilder)\
**Post date:** [August 25, 2015, 1:02pm UTC](https://boards.straightdope.com/t/help-with-rsync/728628/3 "2015-08-25T13:02:08Z")

</div>

can too, rsync host:’/dir1/dir2/\*’ /local/file/directory/new

You can add an argument to tell it to ignory any directory, if one gets sucked up in the expansion of \*

Since you are only copying files , you have to do each directory one at a time

Your example was 5 numbered directories… So you would run rsync 5 times.

---

<div class="post-metadata">

**Author:** ![Kyrie\_Eleison](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kyrie_eleison/32/7682_2.png) [@Kyrie\_Eleison](https://boards.straightdope.com/u/Kyrie_Eleison)\
**Post date:** [August 25, 2015, 2:27pm UTC](https://boards.straightdope.com/t/help-with-rsync/728628/4 "2015-08-25T14:27:17Z")

</div>

Assuming all of your account numbers are uniformly 5 digits, you can get them all in one rsync command using something like this on the destination host:

rsync -rv --include=’[0-9][0-9][0-9][0-9][0-9]/’ --include=‘INBOX’ --exclude=’_’ 'fromhost:/var/spool/tv/files/default/_’ /home/table/public\_html/backpack/wp-content/uploads/production/orders

It would be nice if rsync offered better regular expression support, so you could say to include ‘[0-9]+/’ to match any all-digit directory instead of repeating [0-9] exactly five times, but instead it seems to offer some sort of weird and limiting combination of regexp and globbing.

---

<div class="post-metadata">

**Author:** ![Kyrie\_Eleison](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kyrie_eleison/32/7682_2.png) [@Kyrie\_Eleison](https://boards.straightdope.com/u/Kyrie_Eleison)\
**Post date:** [August 25, 2015, 2:44pm UTC](https://boards.straightdope.com/t/help-with-rsync/728628/5 "2015-08-25T14:44:12Z")

</div>

Too late to edit: Please ignore my last post. I just realized that I misread the OP, and that the INBOXes are directories whose contents are to be copied, and not the files themselves. My mistake, sorry; my response isn’t applicable.
