I wrote a patched version of the imscp backup script. I modified the script to keep the backups for seven days.
The original file is located at: /var/www/imscp/engine/backup/imscp-backup-all
Make a backup of the file, before you patch it.
Display MorePerl
- #!/usr/bin/perl
- # i-MSCP - internet Multi Server Control Panel
- # Copyright (C) 2010-2013 by internet Multi Server Control Panel
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # 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
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- #
- # @category i-MSCP
- # @copyright 2010-2013 by i-MSCP | http://i-mscp.net
- # @author Daniel Andreca <sci2tech@gmail.com>
- # @link http://i-mscp.net i-MSCP Home Site
- # @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2
- use strict;
- use warnings;
- use FindBin;
- use lib "$FindBin::Bin/..";
- use lib "$FindBin::Bin/../PerlLib";
- use iMSCP::Debug;
- use iMSCP::Boot;
- use iMSCP::Execute;
- use iMSCP::Mail;
- use iMSCP::Dir;
- use Data::Dumper;
- newDebug('imscp-backup-all.log');
- our $command = {
- pbzip2 => {extension => 'bz2', command => 'CMD_PBZIP'},
- bzip2 => {extension => 'bz2', command => 'CMD_BZIP'},
- gzip => {extension => 'gz', command => 'CMD_GZIP'},
- lzma => {extension => 'lzma', command => 'CMD_LZMA'},
- xz => {extension => 'xz', command => 'CMD_XZ'}
- };
- sub backup_start_up {
- umask(027);
- iMSCP::Boot->new()->init({nolock => 'yes'});
- 0;
- }
- sub backup{
- my $rs = 0;
- my ($stdout, $stderr);
- if ($main::imscpConfig{'BACKUP_DOMAINS'} ne 'yes') {
- return 0;
- }
- unless ($main::imscpConfig{ZIP} =~ /^(pbzip2|bzip2|gzip|lzma|xz)$/i) {
- my $msg = "Backup algorithm not supported: $main::imscpConfig{ZIP}!";
- error($msg);
- return 1;
- }
- my $sql = "
- SELECT
- *
- FROM
- `domain` AS t1,
- `admin` AS t2
- WHERE
- t1.domain_status = 'ok'
- AND
- t1.domain_admin_id = t2.admin_id
- AND
- t1.allowbackup != 'no'
- ";
- my $rdata = iMSCP::Database->new()->factory()->doQuery('domain_name', $sql);
- if (ref $rdata ne 'HASH'){
- error("$rdata");
- $rs = 1;
- } else {
- for (keys %$rdata) {
- iMSCP::Boot->new()->lock();
- if ($rdata->{$_}->{allowbackup} !~ m/^no$/i) {
- my $hDir = $main::imscpConfig{USER_HOME_DIR}."/$_";
- my $bkpDir = "$hDir/backups";
- my $rv |= iMSCP::Dir->new( dirname => $bkpDir)->make({
- user => $main::imscpConfig{ROOT_USER},
- group => $main::imscpConfig{ROOT_GROUP},
- mode => 0755
- });
- $rs |= $rv;
- if($rv){
- iMSCP::Boot->new()->unlock();
- next ;
- }
- # cbxk1xg patch to save backups for 7 days.
- $rs |= execute("find $bkpDir/* -maxdepth 0 -type f -mtime +7 -print | xargs -r /bin/rm -v", \$stdout, \$stderr);
- # $rs |= execute("$main::imscpConfig{'CMD_RM'} -rf $bkpDir/*", \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr;
- use POSIX qw(strftime);
- my $ext = $command->{lc($main::imscpConfig{ZIP})}->{extension};
- my $date = strftime "%Y.%m.%d-%H-%M", localtime;
- if ($rdata->{$_}->{allowbackup} =~ m/full|dmn/i) {
- my @cmd = (
- lc($main::imscpConfig{CMD_TAR}),
- "--create --directory=$hDir",
- "--use-compress-program=" . lc($main::imscpConfig{ZIP}),
- "--file=$bkpDir/$_-backup-$date.tar.$ext",
- "--exclude=logs",
- "--exclude=phptmp",
- "--exclude=backups",
- "--exclude=domain_disable_page",
- ". "
- );
- my $rs |= execute(join(' ', @cmd), \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr;
- my $file = iMSCP::File->new(filename => "$bkpDir/$_-backup-$date.tar.$ext");
- $rs |= $file->mode(0666);
- $rs |= $file->owner($main::imscpConfig{ROOT_USER}, $main::imscpConfig{ROOT_GROUP});
- }
- if (
- $rdata->{$_}->{allowbackup} =~ m/full|sql/i
- &&
- iMSCP::Database->new()->factory()->can('dumpdb')
- ) {
- $sql = "SELECT `sqld_id`, `sqld_name` FROM `sql_database` WHERE `domain_id` = ?";
- my $dbData = iMSCP::Database->new()->factory()->doQuery('sqld_name', $sql, $rdata->{$_}->{domain_id});
- if (ref $dbData ne 'HASH'){
- error("$dbData");
- $rs |= 1;
- iMSCP::Boot->new()->unlock();
- next;
- }
- for (keys %$dbData) {
- my $date = strftime "%Y.%m.%d-%H-%M", localtime; # cbxk1xg patch to include the date in the file name
- my $cmd = $main::imscpConfig{$command->{$main::imscpConfig{ZIP}}->{command}}." --force \'$bkpDir/$_-backup-$date.sql\'";
- $rs |= iMSCP::Database->new()->factory()->dumpdb($_, "$bkpDir/$_-backup-$date.sql");
- my $file = iMSCP::File->new(filename => "$bkpDir/$_-backup-$date.sql");
- $rs |= $file->mode(0666);
- $rs |= $file->owner($main::imscpConfig{ROOT_USER}, $main::imscpConfig{ROOT_GROUP});
- $rs |= execute($cmd, \$stdout, \$stderr);
- debug("$stdout") if $stdout;
- error("$stderr") if $stderr;
- error("Can not dump $_") if (!$stderr && $rs);
- }
- }
- }
- iMSCP::Boot->new()->unlock();
- }
- }
- my @warnings = getMessageByType('WARNING');
- my @errors = getMessageByType('ERROR');
- my @all = (@warnings, @errors);
- iMSCP::Mail->new()->errmsg("@all") if(scalar @all > 0 );
- $rs;
- }
- my $rs = 0;
- exit 1 if backup_start_up();
- $rs |= backup();
- exit $rs;
Hello ;
The problem is that we have some customers with bunch of data. Imagine an user with a total of 5 Go to backup. So 5 * 7 = 35 Go... Now let imagine many users with such amount of data to backup...
The whole script must be rewritten but before, we must take some decisions on how to re-implement backup feature. From my side, I always thought that any backup task should be left to the administrator care. Any solution implemented directly in i-MSCP will never correspond to all administrators needs.
Thank you for using i-MSCP.