title: Loop through directories and rsync contents
body: <p>I'm looking to rsync only specific files and directories from a cpanel backup to a remote server.</p>
  
  <p>The basic structure is:</p>
  
  <pre><code>/backup/cpbackup/daily/USERNAME
  </code></pre>
  
  <p>from within USERNAME directory I want to backup</p>
  
  <pre><code>../USERNAME/mysql/USERNAME.sql
  </code></pre>
  
  <p>and also a folder (containing files and subfolders)</p>
  
  <pre><code>../USERNAME/homedir/siteassets
  </code></pre>
  
  <p>so I end up on my remote server with:</p>
  
  <pre><code>/USERNAME/mysql/USERNAME.sql
  /USERNAME/homedir/siteassets
  </code></pre>
  
  <p>I could use wildcards </p>
  
  <pre><code>rsync /backup/cpbackup/daily/*/mysql/*.sql  user@remote.ip.address:servername/
  </code></pre>
  
  <p>but this won't give me the USERNAME folder remotely and will mean all the files end up getting merged. I assume this is possible by iterating through folders with bash or something like tht but thats not my strong point</p>