Author Topic: [MOD] Daily Backup with cron  (Read 19910 times)

0 Members and 1 Guest are viewing this topic.

Offline samvelyano

  • Newbie
  • *
  • Posts: 15
    • View Profile
[MOD] Daily Backup with cron
« on: October 18, 2006, 11:43:21 PM »
Hi,
is there any possibility to setup a crontab to make daily backups?

Thanks
Sam
« Last Edit: February 19, 2007, 06:07:11 PM by mawenzi »

Offline Acidgod

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 2.421
  • It's me?
    • View Profile
    • Flash-Webdesign
Re: Daily Backup with cron
« Reply #1 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?

Offline samvelyano

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Daily Backup with cron
« Reply #2 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

Offline Acidgod

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 2.421
  • It's me?
    • View Profile
    • Flash-Webdesign
Re: Daily Backup with cron
« Reply #3 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*

Offline samvelyano

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Daily Backup with cron
« Reply #4 on: October 19, 2006, 10:54:48 AM »
cool  :)
vielen dank

Grüsse
Sam

Offline KurtW

  • 4images Guru
  • *******
  • Posts: 2.778
    • View Profile
    • Malediven-Bilder ~~Dreams~~
Re: Daily Backup with cron
« Reply #5 on: October 19, 2006, 04:09:06 PM »
Hasllo,

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

Daaaaaaanke schon mal.....

Gruß
Kurt

Offline Acidgod

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 2.421
  • It's me?
    • View Profile
    • Flash-Webdesign
Re: Daily Backup with cron
« Reply #6 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...

Offline honda2000

  • 4images Guru
  • *******
  • Posts: 3.263
    • View Profile
    • Wir machen Internet!
Re: Daily Backup with cron
« Reply #7 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

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Daily Backup with cron
« Reply #8 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

Offline Acidgod

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 2.421
  • It's me?
    • View Profile
    • Flash-Webdesign
Re: Daily Backup with cron
« Reply #9 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:

Offline samvelyano

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Daily Backup with cron
« Reply #10 on: October 19, 2006, 07:16:44 PM »
Perfect!
vielen Dank

Grüsse
Sam

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [MOD] Daily Backup with cron
« Reply #11 on: February 19, 2007, 06:11:04 PM »
This topic has been moved to Mods & Plugins (Releases & Support) !
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline UFOSWORLD

  • Full Member
  • ***
  • Posts: 102
    • View Profile
Re: [MOD] Daily Backup with cron
« Reply #12 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