Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-11-10 22:55:03

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

One-click DB backup?

One of my clients saw a demo by another web developer who had a global link on all control panels that said “Download backup now.”

We have automated hosting backups, but the client thought it was neat enough to ask for. I think he is afraid I’ll be hit by a bus and all of his data will be lost.

Is this possible in TXP? I have installed rss_admin_db_manager but am wondering if it’s possible to make it a single-step client-side download.

Last edited by maruchan (2010-11-10 23:19:15)

Offline

#2 2010-11-11 01:01:29

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: One-click DB backup?

How about a cron job to do the backup and email it to the client. Zero-step backup.


Code is topiary

Offline

#3 2010-11-11 01:21:21

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: One-click DB backup?

lol, not sure why I didn’t think of that. Right now I have a cron job that sends a bunch of his backups to me :-D

Thanks!

Offline

#4 2010-11-29 21:35:04

nabrown78
Member
From: Northampton, MA, USA
Registered: 2006-10-04
Posts: 294
Website

Re: One-click DB backup?

I’ve been trying to get a cron job set up to email TXP database backups to me. I’ve tried the open-source AutoMySqlBackup script with mixed success. Do either of you have a script you are using that I could poach, or any other tips or advice?

Thanks!

Offline

#5 2010-11-29 21:50:17

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: One-click DB backup?

The client I mentioned is actually using a different CMS for the time being, but I’m looking at using TXP there in the future.

So I’m afraid his current emailing-backups solution is just a plugin for another CMS.

What problems are you having with the AutoMySqlBackup script? I heard that worked pretty well.

I also remembered this thread and wonder how hard it would be to combine one of those two-liners with some PHP method of emailing the .sql file to you.

Offline

#6 2010-11-29 22:54:19

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: One-click DB backup?

nabrown78 wrote:

I’ve been trying to get a cron job set up to email TXP database backups to me. I’ve tried the open-source AutoMySqlBackup script with mixed success. Do either of you have a script you are using that I could poach, or any other tips or advice?

Sorry, I’ve only ever used cron to store backups on disk, not to email them.


Code is topiary

Offline

#7 2010-11-29 23:09:02

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: One-click DB backup?

Nora, are you able to install “mutt” on your server (or is it already installed)? If so, this problem gets simpler to solve.

Last edited by maruchan (2010-11-29 23:09:18)

Offline

#8 2010-11-29 23:17:53

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: One-click DB backup?

I should have kept going…anyway, the AutoMySQLBackup script seemed kinda extensive, so maybe this one is worth a try. It requires Mutt and a properly-configured mail transfer agent, but most web hosts shouldn’t have problems with this.

Code from here (save as backup.php or whatever, then cron it)

#!/usr/bin/env php
<?php
/**
* Poor man's mysql backup script!
*
* Needs php(-cli), mysqldump, gzip, mutt and a local MTA.
*
* @category Backup
* @package backup
* @author Till Klampaeckel <till@php.net>
* @license New BSD License
* @version 0.1.0
* @link http://github.com/till/mysql-backup
*/

/**
* Database configuration.
*/
$user = 'root';
$pass = '';
$server = 'localhost';

/**
* Email configuration
*/
$email = 'email@example.org';
$cc = '';

if (!extension_loaded('mysql')) {
    echo "Backup script needs mysql.so to run.";
    exit(1);
}

$exec = array('mysqldump', 'gzip', 'mutt');

foreach ($exec as $exe) {
    if (!file_exists($exe)) {
        echo "Backup script needs {$exe} to run.";
        exit(1);
    }
    if (!is_executable($exe)) {
        echo "Cannot run {$exe}.";
        exit(1);
    }
}

$conn = mysql_connect($server, $user, $pass);
if (!$conn) {
    echo 'Could not connect.';
    exit(1);
}

$result = mysql_query('SHOW DATABASES');

$today = date('Y-m-d');
$store = "./backup_{$today}";
@mkdir($store);

$attachments = array();

while ($row = mysql_fetch_array($result)) {
    $db = $row['Database'];

    echo "Backup: {$db}\n";
    exec("mysqldump -h {$server} -u {$user} -p{$pass} {$db} > {$store}/{$db}.sql");
    exec("gzip {$store}/{$db}.sql");

    $attachments[] = "-a '{$store}/{$db}.sql.gz'";
}

mysql_close($conn);

$body = "Backup: $today";
$subject = '[backup] Backup';

if (empty($email) || $email == 'email@example.org') {
    echo "No email set.";
    exit(1);
}

echo "Sending all backups to: {$email}\n";

$cmd = "echo '{$body}' | mutt -s '{$subject}' " . implode(' ', $attachments);
if (!empty($cc)) {
    $cmd .= " -c {$cc}";
}
$cmd .= " '{$email}'";
exec($cmd);

exit;

Last edited by maruchan (2010-11-29 23:18:38)

Offline

Board footer

Powered by FluxBB