Rsync beats FileZilla hands down


#1

Eventually got round to replacing FileZilla with Rsync and it is fantastic :slight_smile: A single click now updates all local files to the server and takes about five seconds!

It is well worth taking the trouble to setup this method because it completely eliminates the need for FileZilla or other upload file transfer programs.

Rsync stands for “remote sync”, is a remote and local file synchronization tool. It uses an algorithm that minimizes the amount of data copied by only moving the portions of files that have changed.

A link on the localhost home page set $_GET['rsync'] which is tested and if true then Linux RSYNC :

  1. tests local files which need updating
  2. zips required files that want updating
  3. uploads, unzips and overwrites ONLY outdated files
  4. sets all server file permissions, time stamps, etc

Platform:

Desktop: Linux Ubuntu 18.04 with SSH setup
Remote: Linux Ubuntu Server
Linux SSH: Setup
RSYNC: Setup

Usage:

I created the following link on the home-page.php

<?php 
// RSYNC PAGE LINK or Version
  $rsync = '<i class="flr fss"> &nbsp; Ver: 5.505 &nbsp; </i>';
  if(LOCALHOST):
    $rsync = '<a class="flr fss" href="?rsync"> rSync &nbsp; </a>';
  endif;  
  echo '<h5>' .$rsync .'</h5>';'

COMMON FILE

<?php
// COMMON TO ALL PAGES - mine is in the SuperClass
  $rsync = isset($_GET['rsync']) ? true : false;
  if(LOCALHOST && $rsync):
   // SET LOCAL and REMOTE PATHS 
    $HERE   = '/var/www/EXAMPLE.COM/src_files/'; 
    $THERE  = 'SSH_ROOT_USER@123.123.123.123:/var/www/EXAMPLE.COM/src_files/';
    $USER   = 'SSH_USER';  
    $PWORD  = 'SSH_PASSWORD';

    $tmp    = '/usr/bin/rsync -ratlz --rsh="/usr/bin/sshpass -p $PWORD ssh -o StrictHostKeyChecking=no -l $USER" $HERE $THERE';

	$ok = exec($tmp);
  endif;

SPECIAL NOTE:

To prevent the SSH password from being entered every time I used the following:


#2

So, what’s the usecase? Looks good for backups, but i prefer using GIT for deployment.

And why do you disable the security feature? It’s relatively easy to just create the keys on both sides and use encryption.


#3

I develop websites locally and instead of using FileZilla for uploading to online have started to use Rsync which is a lot quicker.

I use the online files as my Github.

The security feature is disabled temporarily because I have yet to correctly set SSH… maybe tomorrow :slight_smile:


#4

I use rsync as well, but I never overwrite the current website with new files, because while you’re uploading you’re in an intermediate state where files of the old version are mixed with files from the new version, and you can’t be sure at all what will happen when a request comes in at that time.

Instead I have a folder releases that contains releases of the website, and a symlink current that points to the currently active version:

For example:

/releases
  /20190219-201211
  /20190222-092912
  /20190301-125432
/current # Symlink to releases/20190301-125432

Then when I upload a new site I create a new directory in releases, upload all files to it, and switch the symlink to it, so the entire changes as one atomical action.

An additional benefit here is that if there is something wrong with the current version you can just point the symlink to a previous release.


#5

There are also tools to automate this, like Capistrano for Rails. I’m sure there’ll be sth similar for PHP.


#6

*: As long as your situation is narrowly defined as ‘you have SFTP access to the remote server’, since this program uses that protocol.