Thread Problem mit Backup-Script (4 answers)
Opened by Frank at 2015-12-14 16:51

Gast Frank
 2015-12-14 16:51
#183237 #183237
Hallo in die Runde,

ich brauche mal Eure Hilfe, da ich mich mit Perl / CGI leider nur rudimentär auskenne. Ich nutzen seit Jahren ein Backup-Script für meine Datenbanken, um diese per CGI schnell auf dem Server zu sichern. Das Script stammt nicht von mir, ich weiss auch nicht mehr, wo ich es mal gefunden hatte. Auf dem alten Server klappte es einwandfrei, seitdem ich auf einen neuen Server umgezogen bin, wird aber nicht mehr die Datenbank gesichert, in der dump.sql steht dann immer nur:

Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

Ich finde aber leider nicht raus, was ich am Script anpassen müsste, damit es wieder läuft. Kann mir ein Profi mal weiterhelfen?

Danke

Frank

Hier das Script:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl -w

################################################
########### ---===> SETTINGS <===--- ###########
################################################
$path = "/www/htdocs/xxxx/backup";
$webpath = "http://www.xxx.de/backup";
$host = "www.xxx.de";
$user = "xxx";
$pass = "xxx";
$db = "d0046c88";
$prefix = "cc";
$compressmethod = "gzip"; # can be bzip2, gzip or nothing
$compresslevel = 1; # 1-9 => Level 1-9, other values => use default
$nice = 15; # 10-20 => Priority 10-20, other values => use default: Note: the higher the value, the lower the priority
$options = "--lock-tables --disable-keys --add-drop-table --extended-insert --add-locks --all-databases --quick";
# '--opt' isn't always including the same options

################################################
########### ---===> THE CORE <===--- ###########
################################################
sub psfind
{
my $name = shift(@_);
return `ps -A` =~ /(?:$name)\s*$/im;
}

$filename = $prefix . "_" . time();

print "content-type: text/html\n\n";

$compresslv = ($compresslevel >= 1 && $compresslevel <= 9) ? " -$compresslevel" : '';
$nice = ($nice >= 10 && $nice <= 20) ? "nice -n$nice " : '';

use Switch;

switch ($compressmethod)
{
case "bzip2"
{
if (psfind('mysqldump|bzip2'))
{
print 'mysqldump or bzip2 running! Try again later.';
exit;
}

print 'MySQL-Export ...';
qx"${nice}mysqldump $options -h $host -u$user -p$pass $db 2>$path/error.txt >$path/$filename.sql";
print " done<br />\n";

print 'Compress the file as BZIP2 ...';
qx"${nice}bzip2$compresslv $path/$filename.sql";
print " done<br />\n";

print "<a href=\"$webpath/$filename.sql.bz2\">Download</a><br />\n";
}

case "gzip"
{
if (psfind('mysqldump|gzip'))
{
print 'mysqldump or gzip running! Try again later.';
exit;
}

print 'MySQL-Export ...';
qx"${nice}mysqldump $options -h $host -u$user -p$pass $db 2>$path/error.txt >$path/dump.sql";
print " done<br />\n";

print 'Compress the file as GZIP ...';
qx"${nice}gzip$compresslv -c $path/dump.sql > $path/$filename.sql.gz";
print " done<br />\n";

print "<a href=\"$webpath/$filename.sql.gz\">Download</a><br />\n";
unlink "$path/dump.sql";
}
else
{
if (psfind('mysqldump'))
{
print 'mysqldump running! Try again later.';
exit;
}

print 'MySQL-Export ...';
qx"${nice}mysqldump $options -h $host -u$user -p$pass $db 2>$path/error.txt >$path/$filename.sql";
print " done<br />\n";

print "<a href=\"$webpath/$filename.sql\">Download</a><br />\n";
}
}

Last edited: 2015-12-14 16:59:34 +0100 (CET)

View full thread Problem mit Backup-Script