Solved

How to make a safe web-based (PHP) backup solution for multiple sites?

Posted on 2013-01-16
6
524 Views
Last Modified: 2013-01-17
Hi Experts!

I run a linux server that has Plesk installed, I have root access via SSH.  I have a few live websites under:

/var/www/vhosts/

Open in new window


I also have some dev sites under:

/var/www/vhosts/[dev_domain]/subdomains/

Open in new window


Now I would like to create a page in my PHP admin app
/var/www/vhosts/[admin_app]/

Open in new window

that allows me to perform backups on the fly, and to view existing backups. The obvious problem I have is the open_basedir() restriction, which is of course in place for good reason.

A backup will comprise of a mysqldump of each web's database, and a zip file containing the website files. I plan to simply exec() from php and use the mysqldump and zip commands.

Ideally I want to run backups from my admin interface (it's mobile-optimised), as well as from a cron jon (running/calling a php file in my admin site).

If I cant get this to work, then the next best solution is to use a cron job to perform the backups, and just use the admin UI to view the backups and to manage them (download, delete, etc).

Either solution is probably going to fall foul of the open_basedir() restriction..

Any ideas for achieving this safely? I don't want to simply remove the open_basedir() restriction as this is a public web server. But I do want the convenience of managing my backups on the go. I don;t want to use Plesk as I am trying to remove my reliance on this software.

Thanks! TheFoot
0
Comment
Question by:Barry Jones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 38785003
> ...  then the next best solution is to use a cron job
no, this is the first solution
write a simple shell script to do the backup and add it to cron, this also has no restrictions as php has (open_basedir)
I'd never use exec() as admin on a web script (php), tooooooo much dangerous
0
 
LVL 12

Author Comment

by:Barry Jones
ID: 38786266
Ok that makes more sense.. thanks.

The configuration for the backups (which sites, and frequency etc) will be stored in a mysql table - how can I retrieve this information via a bash script - can I use PHP from within the bash script?
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 500 total points
ID: 38786344
I'd not use php from within a shell script, however, thinks can be made as complicated as you like ...

if you need data from the database before making a backup you can use the mysql command to retrive data, something like (please make yourself used to the correct syntax):

  mysql -h localhost -u me -e select this from that
0
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 
LVL 12

Author Comment

by:Barry Jones
ID: 38786367
Ok thanks. I found this article which should help me work out how to use the sql data in a structured way:

http://e-university.wisdomjobs.com/shell-scripting/chapter-619-174/using-a-database.html#3547-using-the-database-in-your-scripts

Any comments, or is that the best way to work with the SQL data from a bash script?

Thanks..
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 38786664
the document descrbe a couple of use cases, the ones you need included
so feel free to use any you like

just keep in mind that the output for mysql is different if used in interactive mode or piped to otrher commands (in the latter case mysql is clever enough to omitt all the formatting stuff;-)
0
 
LVL 12

Author Comment

by:Barry Jones
ID: 38786795
Thanks for your help..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question