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";
}
}