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

Posted on 2013-01-16
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:


Open in new window

I also have some dev sites under:


Open in new window

Now I would like to create a page in my PHP 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
Question by:Barry Jones
  • 3
  • 3
LVL 51

Accepted Solution

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
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?
LVL 51

Assisted Solution

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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

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:

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

LVL 51

Expert Comment

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;-)
LVL 12

Author Comment

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

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

912 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

20 Experts available now in Live!

Get 1:1 Help Now