• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 543
  • Last Modified:

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

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
Barry Jones
Barry Jones
  • 3
  • 3
2 Solutions
> ...  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
Barry JonesAuthor Commented:
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?
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Barry JonesAuthor Commented:
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?

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;-)
Barry JonesAuthor Commented:
Thanks for your help..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now