ispCP - Board - Support
Nur SQL Backups ohne Web Backups - Printable Version

+- ispCP - Board - Support (http://www.isp-control.net/forum)
+-- Forum: ispCP Omega International Area (/forum-22.html)
+--- Forum: German Corner (/forum-26.html)
+--- Thread: Nur SQL Backups ohne Web Backups (/thread-3450.html)

Pages: 1 2 3


RE: Nur SQL Backups ohne Web Backups - ZooL - 06-06-2008 01:18 AM

ok vieleicht nehme ich mich dann dem mal an, die bugs zu entfernen und vieleicht fliesst
es doch in eine RC mit ein und wird durch die Community dann weiter entwickelt oder
entbugt... ich fänd es nicht schlecht...

mfg


RE: Nur SQL Backups ohne Web Backups - fulltilt - 06-07-2008 08:57 PM

Also ich habe jetzt die Web Backups ausschliessen können:

/var/www/ispcp/engine/backup/ispcp-backup-all

geändert von:
Code:
if ($zip eq "bzip2") {
$backup_filename = "$dmn_name-backup-$date.tar.bz2";

$backup_cmd = "$cmd_tar --create --directory=$dmn_dir --bzip2 --file=$dmn_dir/$backup_filename --exclude=logs --exclude=phptmp --exclude=backups --exclude=$backup_filename . 2> $dmn_dir/$backup_filename.log";
        }
elsif ($zip eq "gzip") {
$backup_filename = "$dmn_name-backup-$date.tar.gz";

$backup_cmd = "$cmd_tar --create --directory=$dmn_dir --gzip --file=$dmn_dir/$backup_filename --exclude=logs --exclude=phptmp --exclude=backups --exclude=$backup_filename . 2> $dmn_dir/$backup_filename.log";
}

nach:
Code:
if ($zip eq "bzip2") {
$backup_filename = "$dmn_name-backup-$date.tar.bz2";

$backup_cmd = "";
        }
elsif ($zip eq "gzip") {
$backup_filename = "$dmn_name-backup-$date.tar.gz";

$backup_cmd = "";
}

Jetzt würde ich gerne die SQL Backups ungepackt (als .sql) erstellen lassen, kann mir hier jemand helfen - was müsste ich hier ändern?
Code:
my ($db_filename, $db_compresscmd) = (undef, undef);

if ($zip eq "bzip2") {
$db_filename = "$db_backup_file.bz2";
$db_compresscmd = "$main::cfg{'CMD_BZIP'} --force \'$db_backup_file\'";
}
elsif ($zip eq "gzip") {
$db_filename = "$db_backup_file.gz";
$db_compresscmd = "$main::cfg{'CMD_GZIP'} --force \'$db_backup_file\'";
}
else {
push_el(\@main::el, 'backup_all_engine()', "Backup algorithm not supported: $zip");
return 1;
}

$rs = sys_command($db_backupcmd);

if ($rs == 0) {
$rs = setfmode("$db_backup_file", $domain_uid, $domain_gid, 0660);

if ($rs != 0) {
unlink($db_backup_file);
}
else {
$rs = sys_command($db_compresscmd);
return $rs if ($rs != 0);
}
return $rs if ($rs != 0);
}
else {
push_el(\@main::el, 'backup_all_engine()', "ERROR: Failed to backup database $db_name");
unlink($db_backup_file);
}



RE: Nur SQL Backups ohne Web Backups - fulltilt - 06-07-2008 10:26 PM

Das mit den SQL Backups ungepackt habe ich auch hinbekommen.
Allerdings bekomme ich noch die Fehlermeldung zwischendurch ... es werden aber alle SQL Backups angelegt:

Code:
DEBUG: push_el() sub_name: backup_all_engine(), msg: ERROR: tar returned exit status -1, have a look in /var/www/virtual/xxxx.xx/xxxx.xx-backup-2008.06.07-141249.tar.gz.log

Hier ist die komplette Datei falls das jemand testen möchte:
Code:
#!/usr/bin/perl

# ispCP ω (OMEGA) a Virtual Hosting Control Panel
# Copyright (c) 2001-2006 by moleSoftware GmbH
# http://www.molesoftware.com
# Copyright (c) 2006-2007 by isp Control Panel
# http://isp-control.net
#
#
# License:
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of the MPL Mozilla Public License
#    as published by the Free Software Foundation; either version 1.1
#    of the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    MPL Mozilla Public License for more details.
#
#    You may have received a copy of the MPL Mozilla Public License
#    along with this program.
#
#    An on-line copy of the MPL Mozilla Public License can be found
#    http://www.mozilla.org/MPL/MPL-1.1.html
#
#
# The ispCP ω Home Page is at:
#
#    http://isp-control.net
#

use FindBin;
use lib "$FindBin::Bin/..";
require 'ispcp_common_code.pl';

use strict;

use warnings;

sub lock_backup_all_system {

    my ($lock_file) = @_;

    push_el(\@main::el, 'lock_backup_all_system()', 'Starting...');

    if ($main::cfg{'BACKUP_DOMAINS'} ne 'yes') {

        push_el(\@main::el, 'lock_backup_all_system()', 'NOTICE: domain backups are disabled');

        return 2;
    }

    if (-e $lock_file) {

        push_el(\@main::el, 'lock_backup_all_system()', 'ERROR: backup request engine already locked !');

        return 1;

    }

    my $touch_cmd = "$main::cfg{'CMD_TOUCH'} $lock_file";

    my $rs = sys_command($touch_cmd);

    return 1 if ($rs != 0);

    push_el(\@main::el, 'lock_backup_all_system()', 'Ending...');

    return 0;
}


sub unlock_backup_all_system {

    my ($lock_file) = @_;

    push_el(\@main::el, 'unlock_backup_all_system()', 'Starting...');

    my $rs = del_file($lock_file);

    return $rs if ($rs != 0);

    push_el(\@main::el, 'unlock_backup_all_system()', 'Ending...');

    return 0;

}



sub backup_all_start_up {

    my ($lock_file) = @_;

    my ($rs, $rdata) = (undef, undef);

    push_el(\@main::el, 'backup_all_start_up()', 'Starting...');

    $rs = lock_backup_all_system($lock_file);

    return $rs if ($rs != 0);

    # config check;

    $rs = get_conf();

    return $rs if ($rs != 0);

    #
    # getting initial data also must be done here;
    #

    #my $sql = "select * from domain where domain_status = 'ok' ;";

    #($rs, $rdata) = doSQL($sql);

    #return $rs if ($rs != 0);

    push_el(\@main::el, 'backup_all_start_up()', 'Ending...');

    return 0;

}


sub backup_all_shut_down {

    my ($lock_file) = @_;

    my $rs = undef;

    push_el(\@main::el, 'backup_all_shut_down()', 'Starting...');

    $rs = unlock_backup_all_system($lock_file);

    return $rs if ($rs != 0);

    push_el(\@main::el, 'backup_all_shut_down()', 'Ending...');

    return 0;

}

sub err_exit {

    my $el_data = pop_el(\@main::el);

    $main::el_sep = "\t#\t";

    my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);

    print STDERR "$msg\n";

    exit 1;

}

sub backup_all_mail_task {

    my ($rs, $rdata, $sql) = (undef, undef, undef);

    push_el(\@main::el, 'backup_all_mail_task()', 'Starting...');

    $sql = "
        SELECT
                admin_name,
                email
        FROM
            admin
        WHERE
            created_by = 0
    ";

    ($rs, $rdata) = doSQL($sql);

    return $rs if ($rs != 0);

    #
    # no admin data -> no mail message;
    #

    return 0 if (scalar(@$rdata) == 0);

    $rdata = @$rdata[0];

    my $date = get_human_date();

    my ($admin_name, $admin_email) = (@$rdata[0], @$rdata[1]);

    my $dmn_backup_dir = $main::cfg{'BACKUP_FILE_DIR'};

    my $backup_file_list = `ls -la $dmn_backup_dir`;

    my $server_name = $main::cfg{'SERVER_HOSTNAME'};

    my $server_ip = $main::cfg{'BASE_SERVER_IP'};

    my $msg_data = <<MESSAGE_TEXT;
Hey There,

I'm the automatic backup system on your $server_name ($server_ip) server.

Backup task was completed successfully!

File(s) List In ($dmn_backup_dir):

========================================================================
$backup_file_list
========================================================================
MESSAGE_TEXT

    my $out = new MIME::Entity;

    $out -> build(
                From => "Automatic Backup Manager <".$admin_email.">",
                To => $admin_email,
                Subject => "[$date] Backup report.",
                Data => $msg_data,
                'X-Mailer' => "$main::cfg{'VersionH'} Automatic Backup Messanger"
                );

    open MAIL, "| /usr/sbin/sendmail -t -oi";

    $out -> print(\*MAIL);

    close MAIL;

    push_el(\@main::el, 'backup_all_mail_task()', 'Ending...');

    return 0;

}


sub backup_all_engine {

    my ($rs, $rdata, $sql) = (undef, undef, undef);

    my $zip = $main::cfg{ZIP};

    push_el(\@main::el, 'backup_all_engine()', 'Starting...');


    $sql = "
        SELECT
            t1.domain_id,
            t1.domain_name,
            t1.domain_status,
            t1.domain_uid,
            t1.domain_gid,
            t2.admin_name,
            t2.email
        FROM
            domain AS t1,
            admin AS t2
        WHERE
                t1.domain_status    = 'ok'
            AND    t1.domain_admin_id    = t2.admin_id
        ORDER BY
            t1.domain_id
    ";

    ($rs, $rdata) = doSQL($sql);

    return $rs if ($rs != 0);

    my $cmd_tar = $main::cfg{'CMD_TAR'};

    my $cmd_rm = $main::cfg{'CMD_RM'};

    my $cmd_mv = $main::cfg{'CMD_MV'};

    my $httpd_uid = $main::cfg{'APACHE_USER'};

    my $httpd_gid = $main::cfg{'APACHE_GROUP'};

    my ($backup_filename, $backup_cmd) = (undef, undef);

    foreach (@$rdata) {

        my ($dmn_id, $dmn_name, $dmn_status, $domain_uid, $domain_gid, $admin_name, $admin_email) = (@$_[0], @$_[1], @$_[2], @$_[3], @$_[4], @$_[5], @$_[6]);

        my $date = get_human_date();

        my $dmn_dir = $main::cfg{'APACHE_WWW_DIR'}."/$dmn_name";

        my $dmn_backup_dir = $main::cfg{'APACHE_WWW_DIR'}."/$dmn_name/backups";

        if ($zip eq "bzip2") {
            $backup_filename = "$dmn_name-backup-$date.tar.bz2";

            $backup_cmd = "";
        }
        elsif ($zip eq "gzip") {
            $backup_filename = "$dmn_name-backup-$date.tar.gz";

            $backup_cmd = "";
        }

        #
        # User Database Backup
        #

        if (! -d $dmn_backup_dir) {
            $rs = make_dir($dmn_backup_dir, $domain_uid, $domain_gid, 0770);

            return $rs if ($rs != 0);
        }

        #
        # User Database Backup
        # Vorgehensweise - zu der Domain die entsprechenden Datenbanken aus der ISPCP-DB auslesen
        # MYSQLDUMP mit den Datenbanken durchführen und die Ausgabe in das Backup-Verzeichnis umleiten
        #

        $sql="SELECT sqld_id, sqld_name FROM sql_database WHERE domain_id=$dmn_id";
        ($rs,my $rdata3) = doSQL($sql);

        foreach(@$rdata3) {
            my $db_id=@$_[0];
            my $db_name=@$_[1];
            $sql = "SELECT sqlu_name, sqlu_pass FROM sql_user WHERE sqld_id=$db_id LIMIT 1";
            ($rs,my $rdata2) = doSQL($sql);
            my $dbuser = "";
            my $dbpass = "";

            if (@$rdata2) {
                foreach(@$rdata2) {
                    $dbuser = @$_[0];
                    $dbpass = @$_[1];
                }
                if ($dbuser && $dbpass) {
                    my $db_backup_file = "$dmn_backup_dir/$db_name.sql";
                    my $db_backupcmd = "$main::cfg{'CMD_MYSQLDUMP'} --add-drop-table --allow-keywords --quote-names -u\'$dbuser\' -p\'$dbpass\' \'$db_name\' >\'$db_backup_file\'";

                    my ($db_filename, $db_compresscmd) = (undef, undef);

                    if ($zip eq "bzip2") {
                        $db_filename = "$db_backup_file.sql";
                        
                    }
                    elsif ($zip eq "gzip") {
                        $db_filename = "$db_backup_file.sql";
                        
                    }
                    else {
                        push_el(\@main::el, 'backup_all_engine()', "Backup algorithm not supported: $zip");

                        return 1;
                    }

                    $rs = sys_command($db_backupcmd);

                    if ($rs == 0) {
                        $rs = setfmode("$db_backup_file", $domain_uid, $domain_gid, 0660);

                        if ($rs != 0) {
                            unlink($db_backup_file);
                        }
                        
                        return $rs if ($rs != 0);
                    }
                    else {
                        push_el(\@main::el, 'backup_all_engine()', "ERROR: Failed to backup database $db_name");
                        unlink($db_backup_file);
                    }
                }
            }
    
}
        $rs = sys_command($backup_cmd);

        # do not return if backup throws an error, otherwise other domains will not be backuped
        if ($rs == 0) { # everything ok


            $rs = sys_command("$cmd_mv -f $dmn_dir/$backup_filename $dmn_backup_dir");

            return $rs if ($rs != 0);

            $rs = setfmode("$dmn_backup_dir/$backup_filename", $domain_uid, $domain_gid, 0660);

            return $rs if ($rs != 0);

        } else { # some error occurred

            push_el(\@main::el, 'backup_all_engine()', "ERROR: tar returned exit status $rs, have a look in $dmn_dir/$backup_filename.log");

                        if ( -e "$dmn_dir/$backup_filename" ) {

                            $rs = del_file("$dmn_dir/$backup_filename");

                            return $rs if ($rs != 0);

                        }

                }

    }

    push_el(\@main::el, 'backup_all_engine()', 'Ending...');

    return 0;

}


my $rs = undef;

my $proceed = $ARGV[0];


if (!defined($proceed) || $proceed eq '') {

    push_el(\@main::el, 'main()', "ERROR: Missing Input Data! Please provide appropriate command line parameter(s)!");

    err_exit();

}

if ($proceed ne 'yes') {

    push_el(\@main::el, 'main()', "NOTE: If you want full backup of your domain data, please run this script with 'yes' command line parameter!");

    err_exit();

}

my $backup_lock_file = "/tmp/ispcp-backup-all.lock";

$rs = backup_all_start_up($backup_lock_file);

err_exit() if ($rs != 0 && $rs != 2);

exit 0 if ($rs == 2); # $rs == 2 when backups are disabled

$rs = backup_all_engine();

err_exit() if ($rs != 0);

$rs = backup_all_shut_down($backup_lock_file);

err_exit() if ($rs != 0);

exit 0;



RE: Nur SQL Backups ohne Web Backups - xister - 06-10-2008 09:23 PM

Ich habe das Script (http://hsp-52.hspserver.com/backup.htm) Zuhause leider nicht mehr gefunden aber mich mit dem damaligen Entwickler kurzgeschlossen.
Er stellt uns seinen Code zur freien Verwendung in ispCP sehr gerne bereit.

Er selber programmiert kein php mehr und der Code (beruht noch auf vhcs) ist auch sehr unschön und buggy wie er selber schreibt. Aber vielleicht könnt ihr ja etwas draus machen.

Die Probleme mit dem Modul waren u.A.:

- Fragwürdige Sicherheit (Aufruf mit falschen Parametern um fremden Inhalt rückzusichern)
- Keine Einschränkung der Verwendung. (Es gab 2 Nutzer, die pausenlos Rücksicherungen machten. Findet der Server nicht so schön.)

Hier der Link zum Code:
http://www.diskussionspunkt.de/vhcs_team.tar.bz2

btw:
Vielleicht mag ja auch jemand diesen Text ins englische Forum posten Smile


RE: Nur SQL Backups ohne Web Backups - Zothos - 06-10-2008 10:03 PM

nice, schau ich mir gleich mal an. Smile


RE: Nur SQL Backups ohne Web Backups - Zothos - 06-11-2008 06:19 AM

also der code ist wirklich schlecht. Wird eine rießen arbeit das anzupassen. Würde fast vorschlagen wir nehmen seine engine sachen und den rest bauen wir selbst.


RE: Nur SQL Backups ohne Web Backups - ZooL - 06-11-2008 06:37 AM

Neu coden ist meistens einfacher.
Und bugfreier als überarbeitung.

danke dir Zothos für das Statement.

MFG


RE: Nur SQL Backups ohne Web Backups - xister - 06-11-2008 04:37 PM

Denke auch, man kann sich besser Anregungen vom Code und Design holen kann und dann halt selbst anfängt zu coden. Zumal man dann selber besser durchsteigt und weiß, wo was hakt.


RE: Nur SQL Backups ohne Web Backups - Zothos - 06-11-2008 05:26 PM

hier mal ein paar gedanken zu dieser neuen Funktionalität.

- admin kann das ganze global ein und aus schalten
- admin kann das ganze auch für jeden reseller ein und auschalten
- Reseller kann das ganze für seine Kunden ein und ausschalten global
- Reseller kann im hosting plan definieren ob backups ja / nein
- Auch nachträglich ein und auschaltbar über edit
- 3 backup arten domain files | mysql | mail
- Zurückspielen der 3

So das war kurz und knackig die gui, der deamon wird lustiger. Denn das was er gemacht hat ist nur ne quick and dirty lösung. Also nicht zu gebrauchen.

- Anpassung des ispcp-backup-all an die obigen changes

Die eigentliche gui und die db hintendran ist schnell erstellt. Doch der daemon wird interessant, Also, lasst mal hören was ihr davon haltet. Wobei anzumerken ist, frühestens in der rc6/1.0 kann das ganze in den trunk kommen.


RE: Nur SQL Backups ohne Web Backups - xister - 06-11-2008 05:32 PM

ispcp-backup-all wird ohnehin komplett neu geschrieben oder? Smile
Die ist doch auch mehr oder weniger schön und überbleibsel von damals, oder?

Vielleicht sollte der Admin noch festlegen können, wieviele Versionsstände gesichert werden.

Ansonsten ist von mir aus, dem nichts mehr hinzuzufügen.