Current time: 11-27-2024, 03:01 PM Hello There, Guest! (LoginRegister)


Post Reply 
Nur SQL Backups ohne Web Backups
Author Message
fulltilt Offline
Member
***

Posts: 1,225
Joined: Apr 2007
Reputation: 5
Post: #13
RE: Nur SQL Backups ohne Web Backups
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;
(This post was last modified: 06-07-2008 10:27 PM by fulltilt.)
06-07-2008 10:26 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Nur SQL Backups ohne Web Backups - fulltilt - 06-07-2008 10:26 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)