Solved

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

Posted on 2013-01-16
6
478 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
  • 3
  • 3
6 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
Comment Utility
> ...  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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 12

Author Comment

by:Barry Jones
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your help..
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now