Skip to main content
  1. All Posts/

syncfiles

Tools Open Source Sync WordPress

Syncfiles – Easily rsync WordPress theme files

Easily rsync WordPress theme files up and down from your local machine to your
remote server, using a function named syncfiles.

Features

  • Loads a syncfiles.zsh file from the current folder, which sets some
    variables that are specific for that site, eg:

    • user (cPanel username)
    • host (domain name)
    • the remote base directory (eg public_html/)
    • the theme slug (eg themename)
    • the rsync arguments (eg -avzP)
    • excluded files and folders (preprocessor files, backup files, etc.)
  • Optional arguments/flags:
    • Do a dry run
      • -d | --dry | --dryrun | --dry-run
      • Dry-run is more critical than syncing downwards, so gets the -d
    •   <li>
          Specify a specific pattern <ul dir="auto">
            <li>
              <code>-o=*</code> | <code>--only=*</code>
            </li>
            <li>
              Wildcards need escaped
            </li>
            <li>
              ⚠️ Empty folders will downloaded. Not figured out how to avoid that.
            </li>
            <li>
              Example usage: <ul dir="auto">
                <li>
                  <code>syncfiles --down --only=*.php</code>
                </li>
                <li>
                  <code>syncfiles --down --only=navigation.js</code>
                </li>
              </ul>
            </li>
          </ul>
        </li>
        
        <li>
          Specify that you want to sync downwards <ul dir="auto">
            <li>
              <code>--down</code> | <code>--pull</code>
            </li>
            <li>
              For when files are on the server and you don&#8217;t have them locally.
            </li>
          </ul>
        </li>
        
        <li>
          Specify that you want to sync upwards <ul dir="auto">
            <li>
              <code>--up</code> | <code>--push</code>
            </li>
            <li>
              This is the default behaviour
            </li>
          </ul>
        </li>
        
        <li>
          Include the <code>/acf-json/</code> folder <ul dir="auto">
            <li>
              <code>--inc-acf</code>
            </li>
          </ul>
        </li>
        
        <li>
          Override the main arguments <ul dir="auto">
            <li>
              <code>-a=*</code> | <code>--args=*</code>
            </li>
            <li>
              <a rel="nofollow noopener" target="_blank" href="https://devhints.io/rsync">https://devhints.io/rsync</a>
            </li>
          </ul>
        </li>
        
        <li>
          Specify the SSH port <ul dir="auto">
            <li>
              <code>-p=*</code> | <code>--port=*</code>
            </li>
            <li>
              Rarely non-default, always port 22 on ProISP
            </li>
          </ul>
        </li>
        
        <li>
          Sync the WordPress uploads folder <ul dir="auto">
            <li>
              <code>--uploads</code>
            </li>
            <li>
              Changes to uploads folder and syncs it in the direction chosen.
            </li>
          </ul>
        </li>
        
        <li>
          Sync the WordPress plugins folder <ul dir="auto">
            <li>
              <code>--plugins</code>
            </li>
            <li>
              Changes to plugins folder and syncs it in the direction chosen.
            </li>
          </ul>
        </li>
        
        <li>
          Debug <ul dir="auto">
            <li>
              <code>--debug</code>
            </li>
            <li>
              Echo the full string just so we can check it, nothing fancy.
            </li>
          </ul>
        </li>
      </ul>
      

    Requirements

    You must have authorised your SSH key on the remote machine.

    To-do

    • Delete twenty-x themes, hello dolly, and akismet
    • Automatically set WordPress’ environment