CHips L MINI SHELL

CHips L pro

Current Path : /proc/3/task/3/cwd/proc/2/root/proc/3/root/scripts/
Upload File :
Current File : //proc/3/task/3/cwd/proc/2/root/proc/3/root/scripts/update_backup_config_66

#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - scripts/update_backup_config_66           Copyright 2017 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package scripts::update_backup_config_66;

use strict;
use warnings;

use Cpanel::Logger;

use YAML::XS;

our $logger;
our $BACKUP_CONFIG_FILE       = '/var/cpanel/backups/config';
our $BACKUP_CONFIG_CACHE_FILE = '/var/cpanel/backups/config.cache';
our $BACKUP_QUEUE_DIRECTORY   = '/var/cpanel/backups/queue/';

sub new {
    my $pkg  = shift;
    my $self = {};
    bless $self, $pkg;
    return $self;
}

sub run {
    my $self = shift;

    $logger //= Cpanel::Logger->new();

    if ( !-e $BACKUP_CONFIG_FILE ) {

        # This system is *brand* newly installed at v66+; the default will rule.
        $logger->info("Backup configuration doesn't exist; skipping update_backup_config_66");
        return 0;
    }
    my $config_has_changed = 0;
    my $cfg                = YAML::XS::LoadFile($BACKUP_CONFIG_FILE);

    if ( !defined $cfg ) {

        # Something Really Bad happened--the file exists, but is empty. Deeply unlikely.
        $logger->info("Backup configuration file empty; skipping update_backup_config_66");
        return 1;
    }

    if ( $cfg->{'BACKUPENABLE'} eq 'no' && !-e $BACKUP_QUEUE_DIRECTORY ) {

        # Backups have never been run, ever, but this is an upgrade.
        # Default to check for free disk space, if they ever turn it on.
        $cfg->{'CHECK_MIN_FREE_SPACE'} = 1;
        $config_has_changed++;
        $logger->info("Backup config modified to check free disk space");
    }
    else {
        # Backups are running, or were run at least once, then turned off.
        # Keep what is in the config, if anything, or default to *not*
        # check free disk space.
        if ( !defined $cfg->{'CHECK_MIN_FREE_SPACE'} ) {
            $cfg->{'CHECK_MIN_FREE_SPACE'} = 0;
            $config_has_changed++;
            $logger->info("Backup config modified to NOT check free disk space");
        }
    }

    if ($config_has_changed) {
        YAML::XS::DumpFile( $BACKUP_CONFIG_FILE,       $cfg );
        YAML::XS::DumpFile( $BACKUP_CONFIG_CACHE_FILE, $cfg );
        $logger->info("Modified backup configuration saved.");
    }
    else {
        $logger->info("Backup configuration required no modification.");
    }

    return 0;
}

if ( !caller() ) {
    exit __PACKAGE__->run();
}

1;

__END__

=head1 NAME

update_backup_config_66 - adds necessary key to backup configuration

=head1 SYNOPSIS

update_backup_config_66 [options]

  Options:
    -help      print help message
    -x         execute the change

=head1 DESCRIPTION

In cPanel & WHM version 64, we introduced a feature to enable the backup
scripts to check for free disk space before proceeding with backups. The
feature has a toggle to enable it; the default was OFF.

In version 66, the toggle should be ON by default for new installs, or for
any systems where backups have not ever been run before. If backups were
already run on a system, (whether still running or not), keep the existing
behavior, as defined by the user--or if they didn't define it, force it to
OFF.

This script is intended for running after the version 66 upgrade. It will
modify the backup configuration if necessary to force the behavior we want,
and not surprise the user by checking disk space when it wasn't checking
before. Running it manually at any time will not do anything harmful, but
should never be needed.

=cut

Copyright 2K16 - 2K18 Indonesian Hacker Rulez