Jump to content

Looking for a way to run an Rsync command from PHP


elentz

Recommended Posts

I need to use rsync to keep a list of files synced with a server.  I will have many "clients".  On the clients I want to create a webpage where the user can operate a button and run the rsync command.  I have the rsync and ssh setup with passwordless login using a RSA key  The rsync command I can run from a command line or using cron.  All that I have found to do this in php is this:

<?php
$copy = 'rsync -chavzP RcyEJtB2@xxx.xxx.yyy.yyy:/home/PhoneFirmware/ /var/www/html/cqfirmware/';
shell_exec ($copy);
?>

I am open to any other way of doing this.

Thanks for any ideas

 

Link to comment
Share on other sites

Not sure I understand the design here.  Your rsync keeping files up to date on the local machine, correct?  Running a "webserver" in order to have a page with a button that says "Sync" would require a whole bunch of software and configuration on each machine.    What instructions will be provided to each client instructing them on how to navigate to/find the magical "sync" button page?  

Obvious alternatives would be a bash script or even an electron app.

Link to comment
Share on other sites

Yeah, if this was something your client said to do then you should advise them that something automated, like perhaps cron, would be better. Because working for them means more than simply doing what they order - you have knowledge and expertise to offer, not just man-hours.

Link to comment
Share on other sites

Thanks guys for the replies.  I have used the rsync command in a cron job ane it works well.  This particular instance I am reluctant to run this automatically.  It is for updating firmware on IP phones.  I am the provider of the system and the phones.  I am a firm believer if the firmware is working now for your phone and there are no reasons to update it it makes no sense to update.  Conversely I want them to have the option to be able to get the new firmware if necessary.  As the php script is now it provides a blank page and the log file shows that it timed out.  I could write a bash script to query a db to see if they are allowed to update and run that from a cron job.  

Link to comment
Share on other sites

Well in that case I would agree with you: don't deploy firmware updates automatically.

A timeout means the rsync command is taking too long to execute. Is that to be expected?

What you could do instead is run the rsync automatically but don't put the files into the live location. Put them in a staging directory, ready to be deployed when someone presses that button. Exactly how you set up staging and deployment could vary greatly - maybe a simple copy (or local rsync), but I think I would go for a symlink.

Link to comment
Share on other sites

requinix

That's what I figured was happening, taking to long  The whole process could take a few minutes.  So that is out.  But I like the idea  of automatically downloading it with a cron job and using a "staging" directory.  Then the rest would be easy or easier.  Thanks for the idea!!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.