4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: samvelyano on October 18, 2006, 11:43:21 PM

Title: [MOD] Daily Backup with cron
Post by: samvelyano on October 18, 2006, 11:43:21 PM
Hi,
is there any possibility to setup a crontab to make daily backups?

Thanks
Sam
Title: Re: Daily Backup with cron
Post by: Acidgod on October 19, 2006, 09:36:21 AM
Code: [Select]
<?php

$host
"XXXXXXXX";
$db "XXXXXXXX";
$dbuser "XXXXXXXX";
$dbpw "XXXXXXXX";

MYSQL_CONNECT($host$dbuser$dbpw) or die ( "<H3>Datenbankserver nicht erreichbar</H3>");
MYSQL_SELECT_DB($db) or die ( "<H3>Datenbank nicht vorhanden</H3>");

$path getenv('DOCUMENT_ROOT')."/DB_backup";
$result MYSQL_QUERY("SHOW TABLES");
$numrow MYSQL_NUM_ROWS($result);


for(
$i 0;$i $numrow;$i++) {
  
$table date("D");
  
$table .= '.'.MYSQL_RESULT($result,$i);
  echo 
"$table ... ";
  
system(sprintf("mysqldump --opt -h $host -u $dbuser -p$dbpw $db $table | gzip > %s/$table.sql.gz",$path));
  echo 
"DONE <br><br>";
}

MYSQL_CLOSE();

?>

You can use this PHP Script to make a Backup from the DB with a Cronjob... (o:
Do you allso need a Backup of the Files/Images?
Title: Re: Daily Backup with cron
Post by: samvelyano on October 19, 2006, 10:26:54 AM
Hi,
thanks for the script. I've tried to make a backup, but something is wrong, here is the result in 4images_images.sql.gz

Code: [Select]
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

Maybe I'm doing something wrong?
I've created the DB_backup directory and called the cron-script wget http://www.my4imagesite.com/cron.php

Thanks
Sam
Title: Re: Daily Backup with cron
Post by: Acidgod on October 19, 2006, 10:43:33 AM
Ups...
I have @home a newer Version of the Script...
The new Script makes Backups with the day of the week in the Filename and override it weekly...
So you have Backups from the last 7 days...

So you must now wait 7h... )o:

EDIT:
WARUM SCHREIBE ICH IN ENG WENN DU AUS DE BIST? *grübel*
Title: Re: Daily Backup with cron
Post by: samvelyano on October 19, 2006, 10:54:48 AM
cool  :)
vielen dank

Grüsse
Sam
Title: Re: Daily Backup with cron
Post by: KurtW on October 19, 2006, 04:09:06 PM
Hasllo,

das Script wäre auch was für mich :mrgreen:

Daaaaaaanke schon mal.....

Gruß
Kurt
Title: Re: Daily Backup with cron
Post by: Acidgod on October 19, 2006, 04:29:49 PM
Ich habe es bald geschafft, gleich Feierabend und dann noch einkaufen... *g*

Schicke es euch so bald ich wieder daheim bin...
Title: Re: Daily Backup with cron
Post by: honda2000 on October 19, 2006, 06:06:50 PM
warum so lang???

Code: [Select]
<?
exec("mysqldump -u LOGIN -pPASSWORT --add-drop-table LOGIN >dump" . date('Ymd_g_i') . ".sql");
exec("gzip dump" . date('Ymd_g_i') . ".sql");
echo "Backup wurde erstellt!";
?>


exec("mysqldump -u Login -pPASSWORT --add-drop-table LOGIN >dump" . date('Ymd_g_i') . ".sql");
exec("gzip dump" . date('Ymd_g_i') . ".sql");
echo "Backup wurde erstellt!";

das script, unter welchem Namen auch immer von www.cronjob.de um eine bestimmte Zeit / Tag ausführen lassen
Title: Re: Daily Backup with cron
Post by: BartAfterDark on October 19, 2006, 06:13:24 PM
How do I make something that can backup my site once a week and make it overwrite the old backup?

 - Lars
Title: Re: Daily Backup with cron
Post by: Acidgod on October 19, 2006, 06:56:36 PM
warum so lang???

Weil es jede TAbelle einzeln ausliest und sie dann packt, das ist bei großen DB sehr von Vorteil... (o:
Und exec kann nicht jeder benutzen... (o:

Code: [Select]
<?php

$host 
"XXXXXXXX";
$db "XXXXXXXX";
$dbuser "XXXXXXXX";
$dbpw "XXXXXXXX";

MYSQL_CONNECT($host$dbuser$dbpw) or die ( "<H3>Datenbankserver nicht erreichbar</H3>");
MYSQL_SELECT_DB($db) or die ( "<H3>Datenbank nicht vorhanden</H3>");

$path getenv('DOCUMENT_ROOT')."/DB_backup";
$result MYSQL_QUERY("SHOW TABLES");
$numrow MYSQL_NUM_ROWS($result);


for(
$i 0;$i $numrow;$i++) {
  
$date date("D");
  
$table MYSQL_RESULT($result,$i);
  echo 
"$date.$table ... ";
  
system(sprintf("mysqldump --opt -h $host -u $dbuser -p$dbpw $db $table | gzip > %s/$date.$table.sql.gz",$path));
  echo 
"DONE <br><br>";
}

MYSQL_CLOSE();

?>

Das sollte eigentlich funzen...
Viel Spass damit... (o:
Title: Re: Daily Backup with cron
Post by: samvelyano on October 19, 2006, 07:16:44 PM
Perfect!
vielen Dank

Grüsse
Sam
Title: Re: [MOD] Daily Backup with cron
Post by: mawenzi on February 19, 2007, 06:11:04 PM
This topic has been moved to Mods & Plugins (Releases & Support) !
Title: Re: [MOD] Daily Backup with cron
Post by: UFOSWORLD on June 24, 2007, 02:48:58 PM
hab nee datei mir dem Inhalt angelegt...

Code: [Select]
<?php

$host 
"XXXXXXXX";
$db "XXXXXXXX";
$dbuser "XXXXXXXX";
$dbpw "XXXXXXXX";

MYSQL_CONNECT($host$dbuser$dbpw) or die ( "<H3>Datenbankserver nicht erreichbar</H3>");
MYSQL_SELECT_DB($db) or die ( "<H3>Datenbank nicht vorhanden</H3>");

$path getenv('DOCUMENT_ROOT')."/DB_backup";
$result MYSQL_QUERY("SHOW TABLES");
$numrow MYSQL_NUM_ROWS($result);


for(
$i 0;$i $numrow;$i++) {
  
$date date("D");
  
$table MYSQL_RESULT($result,$i);
  echo 
"$date.$table ... ";
  
system(sprintf("mysqldump --opt -h $host -u $dbuser -p$dbpw $db $table | gzip > %s/$date.$table.sql.gz",$path));
  echo 
"DONE <br><br>";
}

MYSQL_CLOSE();

?>

also ich die dann testhalber mal aufgerufen habe... kommt folgende meldung..

Code: [Select]
Sun.4images_categories ...
Warning: system() has been disabled for security reasons in /www/htdocs/xxxx/mysite/cronjob/job.php on line 20
DONE

is das etz gut oder schlecht...  denke das heisst das der system() befehl nicht aktiv ist auf dem Server, auf dem die Seite liegt...
macht er das backup oder nicht ???
kann man den system befehl rauswerfen...  oder ist der elemtar ...  seh ich das richtig das über den das backup gemacht wird??

wenn ja wo sollten die dateien liegen??



merci UFO