• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Just discovered how to utilise RSYNC to eliminate FileZilla

#1
Just discovered how to utilise RSYNC to eliminate FileZilla

For years I have laboriously written code on my Localhost then used FileZilla to update the relevant Server files. 

Although FileZilla is very good it does take quite a few clicks to synchonise all the updated files so... eventually got round to trying RSYNC.  Updating changes now only takes a couple of seconds!!! FileZilla is never used!!!

The web-page update links and function can be used on any CodeIgniter installation.

The following prerequisites does take a bit of trial and error to install but the effort is well rewarded. 

Prerequisites:

1. install RSYNC
2. install Linux SSH
3. Localhost mirror image of the Server files 
4. Upload links on home page banner/footer (only on Localhost web-pages) 

Test for the following GET parameter links:

1. https://my-ci-website.com/web-page?rsync=app 
2. https://my-ci-website.com/web-page?rsync=wri
3. https://my-ci-website.com/web-page?rsync=ass

The main controller tests for above links and if true calls the following function:

PHP Code:
// Controller Web_page

  
$rsync = isset($_GET['rsync']) ? $_GET['rsync'] : false;
 
  
$data['updatedFiles'] = '';
  if(
LOCALHOST && $rsync):
   
$updatedFiles $this->rsync($rsync$DEBUG=TRUE);
   echo 
'<pre>' .print_r($updatedFilesTRUE) .'</pre>';
   
$data['updatedFiles'] = $updatedFiles;
 endif; 

 return 
view('web-page'$data);
}
//endfunc

// ===========================================================
private function rsync
(
 
string $rsync ''
 
bool   $DEBUG FALSE
)
:
string 
{
 
$result '';

 
$HERE  '/var/www/my-ci-website.com/';
  
$THERE 'ssh-root-name@123.321.222.163:';

  switch(
$rsync):
    case 
'wri':
      
$HERE .= 'writable/';
    break;  

    case 
'ass':
     
$HERE .= 'public_html/assets/';
   break;

    
// case 'app':
     
default:
      
$HERE 'app/'// application for CI3.??
     
break;  
  endswitch;  

   
$THERE .= $HERE;
   
$USER   'ssh-root-user';  
   
$PWORD  'ssh-password';
   
   
// START - PHP HereDoc syntax  
   
$tmp = <<< ____EOT
     /usr/bin/rsync -vratlz      \
     --progress \
     --rsh="/usr/bin/sshpass -p  \
     
$PWORD ssh -o               \
     StrictHostKeyChecking=no -l \
     
$USER" \
     
$HERE \
     
$THERE
____EOT;
   
// FINISH - PHP HereDoc syntax  

  // call RSYNC and get parameters by reference
  
exec($tmp$aRefFilesUploaded$iRefResult);

  
// Maybe DEBUG - return updated files
  
if($DEBUG):
    
$result $aRefFilesUploaded;   
  endif; 

  return 
$result;
}
// endfunc 
CI4 Develop Site - progressing nicely - Thank you Smile
https://johns-jokes.cf/pictures

Reply

#2
I’ve used rsync for other stuff. For this I’d probably use git. Have you tried git?
Reply

#3
(03-22-2019, 07:02 PM)skunkbad Wrote: I’ve used rsync for other stuff. For this I’d probably use git. Have you tried git?

Yes I have used Git and it is very useful for version control.

The way I use RSYNC is to develop locally and update latest changes to the Server:


[Image: Screenshot-from-2019-03-23%2010-38-42.png]
CI4 Develop Site - progressing nicely - Thank you Smile
https://johns-jokes.cf/pictures

Reply

#4
For small projects rsync and ftp is not a problem.


My way (basic):
- Git for version control
- Creating a build from the master or an other branch
- upload the build to the server
- set symlinks to the new build
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.