Linux Backup via rsync and PHP Exec Tutorial

Linux Backup via rsync and PHP Exec Tutorial

Linux Backup via rsync and PHP Exec Tutorial

PHP, being the server side language that it is, has access to a lot of what its operating system provides as functionality via its exec method. Please don’t think everything will work though, and more elegant things you find happening “on the edge” of working, may be telling you that they should be written via shell scripts or a language like C maybe.

Curious that no named operating system appeared in the paragraph above, and that is because PHP will work in a variety of operating systems, but we write a command that will only work in Linux varieties (and maybe Unix ones?!) that does backup functionality. If you’ve been reading here lately, and you didn’t fall into your cornflakes, you’ll know our favourite Linux command lately has been “rsync”, and nothing changes about that today. We just encase the same thinking into the scenario where PHP simulates our Linux command typing for us, via the use of an HTML form method=POST to the same PHP code, which checks for the postings up the top of its code, and writes out what happened should you have requested it to do some “Backup Now” (button) functionality.

We ask for …

  • rsync command switches
  • source directory (a remote “@” one of which results in a password to be asked for as well)
  • destination directory

You can see us attempting some user friendliness, by capturing “man rsync” at the Linux prompt into an HTML textarea … but have to admit you need to know what you are doing here, as do any backup operation thoughts. You can do damage, without putting thought into such operations.

We’ll leave you with the PHP programming source code you could call rsync_backup.php and a live run link.


Previous relevant Linux Remote Backup via rsync Tutorial is shown below.

Linux Remote Backup via rsync Tutorial

Linux Remote Backup via rsync Tutorial

A couple of days ago, with Linux Backup via rsync Primer Tutorial as shown below, we used the Linux command “rsync” backup a local disk to a removable disk on a MacBook Pro laptop using a USB connected Seagate Backup Plus Portable Drive.

Today we use that same USB connected Seagate Backup Plus Portable Drive and the same MacBook Pro laptop, but backup a directory (or folder) on a remote web server … the www.rjmprogramming.com.au Linux CentOS web server, to be precise.

The technique used, and great information for this, again, came from Linux.com’s useful link, so thanks for that. These techniques involve the use of ssh (Secure Shell) which we have talked about at this blog with Web Server Access Primer Tutorial. We use ssh a lot to login (the way you might do with telnet) to our www.rjmprogramming.com.au web server, and here it is helping out “rsync” in an “sftp” feeling way.

To backup remotely, if not too much of a load for the live web server, offers great possibilities for piece of mind for the webmasters involved, as you can imagine.

Lately, options related to backup to the “cloud” are becoming more common, and this is an option too, though tend to think it is better to only involve local resources as the backup media.

We think the advantages of using a Linux method of backing up on a Macbook Pro laptop include …

  • Linux processes are not in your face … while you get on with other things in the usual GUI environment
  • able to be run at a time of your choosing (via shell scripting with crontab, or at login via a .profile arrangement, perhaps), even interactively … though Time Machine can do some of this too
  • the backup can run in the background … though Time Machine can do this too
  • the backup process could easily leave you a log
  • Linux backups are capable of handling remote backup tasks and scenarios

… so today’s discussion helps with that last idea in the list above in two parts …

  1. the original remote backup example
  2. ongoing incremental remote backup example

Previous relevant Linux Backup via rsync Primer Tutorial is shown below.

Linux Backup via rsync Primer Tutorial

Linux Backup via rsync Primer Tutorial

On a Macbook Pro laptop you can use the Mac OS X Time Machine approach to backing up your data, as we talked about with Mac Backup Tutorial. However, a Mac OS X laptop has access to an underlying Linux operating system, that has had great software, including backup software, written for it over many years.

What would be the advantages of using a Linux method of backing up on a Macbook Pro laptop? Can think of …

  • Linux processes are not in your face … while you get on with other things in the usual GUI environment
  • able to be run at a time of your choosing (via shell scripting with crontab, or at login via a .profile arrangement, perhaps), even interactively … though Time Machine can do some of this too
  • the backup can run in the background … though Time Machine can do this too
  • the backup process could easily leave you a log
  • Linux backups are capable of handling remote backup tasks and scenarios

Today’s slideshow presentation starts off with a photo of our …

  1. … Seagate Backup Plus Portable Drive β„Ή hooked up to our Macbook Pro via a black USB lead plugged into one of the Macbook Pro USB ports
  2. we start up the Macbook Pro application called Terminal in the Utilities folder of the Applications folder
  3. the Linux command

    df -k

    will show you the disks and removables (of which our Seagate Backup Plus is one), the latter of which normally get a name starting with “/Volumes/” as for our “/Volumes/Laura”

  4. we are going, today, to backup the local MAMP server to the Seagate Backup Plus via

    rsync -r /Applications/MAMP /Volumes/Laura/

    as you can see with β„Ή (and on)

  5. now to indicate some success with this to you, we turn the Firefox web browser to Open File one of the backup HTML files (because it is a step too far to think you will be able to run PHP from the backup disk … perhaps tomorrow) … maybe you remember india_map.html from the series of blog postings ending with PHP Geographical Image Map Yet More Google Charts Tutorial ? … you can see with β„Ή
  6. okay, that works, and so now, what about if india_map.html changes back at the Macbook Pro hard disk’s MAMP’s htdocs folder … we make a change to the <h1>India</h1> heading to <h1>India Map</h1>
  7. so now we are going to incrementally backup the local MAMP server to the Seagate Backup Plus via

    rsync -ruv /Applications/MAMP/ /Volumes/Laura/MAMP/

    as you can see with β„Ή

  8. now to indicate some success with this to you, we turn the Firefox web browser to Open File that same india_map.html HTML file … as you can see with β„Ή

Of course, as with all Linux a

man rsync

command β„Ήβ„Ή helps explain things further, and we hope this tutorial and Linux.com’s useful link is of some help for you too.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , , , , . Bookmark the permalink.

20 Responses to Linux Backup via rsync and PHP Exec Tutorial

  1. online movies says:

    Empathetic for your monstrous inspect, in addition IÒ€ℒm just seriously very good as an alternative to Zune, and consequently optimism them, together with the really very good critical reviews some other players have documented, will let you determine whether it does not take right choice for you.

  2. Useful information. Fortunate me I found your site by chance, and I’m stunned why this twist of fate didn’t came about earlier! I bookmarked it.|

  3. Nouf Taraman says:

    This is a right weblog for would like to uncover out about this subject. You realize a lot its almost challenging to argue along (not that I personally would wantÒ€¦HaHa). You really put the latest spin with a topic thats been discussed for a long time. Great stuff, just fantastic!

  4. Cars says:

    I wish to voice my admiration for your generosity supporting men who must have guidance on this important matter. Your personal commitment to passing the message along appears to be wonderfully powerful and have all the time enabled associates just like me to reach their dreams. Your entire helpful tutorial denotes this much a person like me and much more to my peers. Thank you; from everyone of us.

  5. encouraging says:

    Great awesome issues here. I am very happy to see your post. Thank you so much and i’m having a look forward to touch you. Will you kindly drop me a mail?

  6. Vigorous says:

    F*ckin’ awesome issues here. I am very happy to see your post. Thank you a lot and i am having a look ahead to touch you. Will you kindly drop me a mail?

  7. index says:

    Hello! I’ve been following your blog for some time now and finally got the courage to go ahead and give you a shout out from Huffman Texas! Just wanted to say keep up the great job!|

  8. subjects as well as share it with us. I assume it will certainly aid a great deal of people. Many thanks

  9. Thanks for all of your effort on this site. My aunt really loves engaging in investigation and it’s really simple to grasp why. I know all regarding the compelling tactic you convey effective techniques by means of the web site and even encourage response from the others about this idea so our simple princess is undoubtedly discovering so much. Have fun with the rest of the new year. You’re performing a glorious job.

  10. shop says:

    Thank you for another informative web site. Where else may I am getting that kind of info written in such an ideal way? I’ve a project that I’m simply now working on, and I’ve been at the glance out for such information.

  11. Following study some with the weblog posts in your web site now, and i genuinely such as your technique for blogging. I bookmarked it to my bookmark website list and are checking back soon. Pls appear into my internet website likewise and make me aware what you consider.

  12. I precisely wished to thank you extremely much yet once more. I’m not sure the issues that I may have accomplished without the type of creative concepts discussed by you directly on such region. It seemed to be a extremely challenging difficulty for me, but coming across a specialised approach you managed that took me to weep with gladness. Now iÒ€ℒm happy for the info and as nicely , hope which you know what a fantastic job your are doing teaching numerous others through the use of a web site. Far more than likely youÒ€ℒve never got to know all of us.

  13. Hello! I just would wish to offer a huge thumbs up for that great information youÒ€ℒve here during this post. I is going to be returning to your web site to get a lot more soon.

  14. Tech Blogs says:

    Just want to say your article is as surprising. The clearness in your post is just cool and i could assume you are an expert on this subject. Well with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the rewarding work.

  15. super says:

    Only a smiling visitant here to share the love (:, btw outstanding design and style .

  16. impressive says:

    A lot of thanks for all your labor on this website. My aunt really likes managing investigation and it’s really easy to see why. All of us hear all concerning the dynamic method you offer insightful items through your website and in addition cause participation from website visitors on that article plus our princess has been being taught a lot. Enjoy the remaining portion of the new year. You’re carrying out a wonderful job.

  17. Wow! Thank you! I continually needed to write on my site something like that. Can I take a fragment of your post to my website?

  18. I am constantly invstigating online for articles that can help me. Thanks!

  19. Some genuinely fascinating details you might have written. Assisted me a whole lot, just what I was seeking for : D.

  20. Nice read, I just passed this onto a colleague who was doing some research on that. And he actually bought me lunch because I found it for him smile Therefore let me rephrase that: Thanks for lunch!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>