Backing up my db in an easy way

Discuss phpwcms here, please do not post support requests, bug reports, or feature requests! Non-phpwcms questions, discussion goes in General Chat!
Post Reply
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Backing up my db in an easy way

Post by update »

Hi,

yesterday I came across a little nice script to make a backup of the phpwcms db, just by calling it from my web browser (one click)
It stores the sql file at the server and additionally sends it automatically to my email address. Just tested it and it works! 8)

Greetings
claus
rushclub
Posts: 915
Joined: Tue 17. Feb 2004, 18:52

Post by rushclub »

can you tell us, what script it is?

rush
3 (!) Jahre warten reichen mir. Ich bin erst mal weg.
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Post by update »

Hi rushclub
it looks like this:

Code: Select all

<?php
$username = 'xxxxxxx';#db user name
$passwort = 'xxxxxxx';#password for database
$db_name = 'xxxxxxxxxxx';#Name of database
$filename = date(d.'.'.m.'.'.Y);
$mail = 'youremailname@youremaildomain.tld';#your emaiaddress
$Subject = "Backup of Database $db_name at $filename";
system('/usr/bin/mysqldump -u'.$username.' -p'.$passwort.' -h localhost '.$db_name.' | /bin/gzip > '.$filename.'.sql.gz', $fp);

//saves your db.sql, stores it in your web root and sends it as attachment
// to your specified email address (I don't know if someone has to change
// the path to mysqldump too?)

if ($fp==0) echo ''; else echo 'ERROR!!! Es ist ein Fehler aufgetreten';
$filename_n = $filename.'.sql.gz';
$Header = "From: Backup System <$mail>";
$Trenner = md5(uniqid(time()));
$Header .= "\n";
$Header .= "MIME-Version: 1.0";
$Header .= "\n";
$Header .= "Content-Type: multipart/mixed; boundary=$Trenner";
$Header .= "\n\n";
$Header .= "This is a multi-part message in MIME format";
$Header .= "\n";
$Header .= "--$Trenner";
$Header .= "\n";
$Header .= "Content-Type: text/plain";
$Header .= "\n";
$Header .= "Content-Transfer-Encoding: 8bit";
$Header .= "\n\n";
$Header .= "Backup der Datenbank $db_name vom $filename";
$Header .= "\n";
$Header .= "--$Trenner";
$Header .= "\n";
$Header .= "Content-Type: application/x-gzip; name=$filename_n";
$Header .= "\n";
$Header .= "Content-Transfer-Encoding: base64";
$Header .= "\n";
$Header .= "Content-Disposition: attachment; filename=$filename_n";
$Header .= "\n\n";
$Dateiinhalt .= fread(fopen($filename_n, "r"), filesize($filename_n));
$Header .= chunk_split(base64_encode($Dateiinhalt));
$Header .= "\n";
$Header .= "--$Trenner--";
mail($mail, $Subject, "", $Header);
?> 
Greetings
claus
Pappnase

Post by Pappnase »

hello

how about to use

http://www.mysqldumper.de/de/index.php

it's an good tool! and when you're able to work with cronjobs you're able to run it automatic :-)
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Post by update »

Ah :oops:

I just took a seat to tell the world that I've found mysqldumper - - - :lol:
as far as I got it this tool is able to shift all the saved stuff back into a new (old) database too, right? I will check it out - sounds really promising

Greetings
claus

Edit: Perhaps some topic for Q&A?
Pappnase

Post by Pappnase »

hello

will be added in the next days :-)
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Post by update »

Hi
8) :!:
claus
Pappnase

Post by Pappnase »

claus wrote:Ah :oops:

I just took a seat to tell the world that I've found mysqldumper - - - :lol:
as far as I got it this tool is able to shift all the saved stuff back into a new (old) database too, right? I will check it out - sounds really promising

Greetings
claus

Edit: Perhaps some topic for Q&A?
Added :-)

german -> http://faq.phpwcms-docu.de/5_67_de.html
english -> http://faq.phpwcms-docu.de/3_67_en.html
Post Reply