Solved

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

Posted on 2013-01-16
6
509 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
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
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

821 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