The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cpbackup Retention Policy = Poor

Discussion in 'Data Protection' started by krocheck, May 16, 2010.

  1. krocheck

    krocheck Registered

    Joined:
    May 16, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    After many years of using cPanel/WHM and the built in cpbackup utility I have found a vulnerability in its retention policy that can leave backups vulnerable to problems existing on the day of a monthly and/or weekly backup retention copy. I'm not quite sure why its taken me so long to figure this out, but I always felt something was fishy.

    I take issue with the 'Copying daily backups to monthly backups for retention.'. Isn't the point of retention for there to be multiple distinct backups available at all times? If we're simply copying the daily backup to weekly and monthly AND that happens on the same day, there is in fact no retention in the backups.

    I have put into place a modified version of cpbackup on my servers and I'd like input on this so we can get this problem fixed if there is some consensus.

    Since I run off-site backups, if the weekly and monthly backups are out of date, then they also get sent in the same run. This can lead of cpbackup running multiple days in a row to send 3 copies of the server off-site.

    My first fix is to have cpbackup only run a daily, weekly, or monthly backup per execution. This is accomplished by systematically checking the dates of last run as the system already does, first the monthly folder, then weekly, then daily. If either of those is out of date then backups run for that folder only. An added tweak I put in was that the weekly backup cannot run less both it and the monthly backup are 6+ days old.

    The only problem I have foreseen is that to restore you would need to verify which of the daily, weekly, and monthly folders has the latest backup since daily is only allowed to run if monthly and weekly do not need to run. The adding benefit of having true retention I think far outweighs the small headache of checking date stamps before selecting an archive to restore.

    Please let me know your thoughts. For your reference, below is the before and after from cpbackup. In my cpbackup the original lines ran 478-570. Note, to avoid issues with cPanel updates, I actually run my cpbackup as '/scripts/cpbackup2' through Cron and removed the regular version from Cron.

    Keith

    Code:
    my $send_message = 0;
    if ( $CONF{'BACKUPINT'} eq "monthly" ) {
        $send_message++;
        if ( !-e "${basedir}/monthly" ) {
            mkdir( "${basedir}/monthly", 0711 );
            backupaccts("${basedir}/monthly");
        }
        else {
            chmod( 0711, "${basedir}/monthly" );
            if ( isolderthen( 29, "${basedir}/monthly" ) ) {
                backupaccts("${basedir}/monthly");
            }
            else {
                $send_message--;
                print "[cpbackup] Monthly Backup is up to date.\n";
            }
        }
    }
    
    if ( $CONF{'BACKUPINT'} eq "weekly" ) {
        $send_message++;
        if ( !-e "${basedir}/weekly" ) {
            mkdir( "${basedir}/weekly", 0711 );
            backupaccts("${basedir}/weekly");
        }
        else {
            chmod( 0711, "${basedir}/weekly" );
            if ( isolderthen( 6, "${basedir}/weekly" ) ) {
                backupaccts("${basedir}/weekly");
            }
            else {
                $send_message--;
                print "[cpbackup] Weekly Backup is up to date.\n";
            }
        }
        if ( $CONF{'BACKUPRETMONTHLY'} ) {
            if ( !-e "${basedir}/monthly" || isolderthen( 29, "${basedir}/monthly" ) ) {
                chmod( 0711, "${basedir}/monthly" );
                if ( $CONF{'BACKUPTYPE'} eq "ftp" ) {
                    mkdir( "${basedir}/monthly", 0711 );
                    backupaccts("${basedir}/monthly");
                }
                else {
                    print "[cpbackup] Copying weekly backups to monthly backups for retention\n";
                    cpusystem( $rsync_bin, $rsyncopts, "--delete", "${basedir}/weekly/", "${basedir}/monthly" );
                }
            }
        }
    }
    
    if ( $CONF{'BACKUPINT'} eq "daily" ) {
        $send_message++;
        if ( !-e "${basedir}/daily" ) {
            mkdir( "${basedir}/daily", 0711 );
            backupaccts("${basedir}/daily");
        }
        else {
            chmod( 0711, "${basedir}/daily" );
            if ( isolderthen( .5, "${basedir}/daily" ) ) {
                backupaccts("${basedir}/daily");
            }
            else {
                $send_message--;
                print "[cpbackup] Daily Backup is up to date.\n";
            }
        }
        if ( $CONF{'BACKUPRETWEEKLY'} ) {
            if ( !-e "${basedir}/weekly" || isolderthen( 6, "${basedir}/weekly" ) ) {
                chmod( 0711, "${basedir}/weekly" );
                if ( $CONF{'BACKUPTYPE'} eq "ftp" ) {
                    mkdir( "${basedir}/weekly", 0711 );
                    backupaccts("${basedir}/weekly");
                }
                else {
                    print "[cpbackup] Copying daily backups to weekly backups for retention\n";
                    cpusystem( $rsync_bin, $rsyncopts, "--delete", "${basedir}/daily/", "${basedir}/weekly" );
                }
            }
        }
        if ( $CONF{'BACKUPRETMONTHLY'} ) {
            if ( !-e "${basedir}/monthly" || isolderthen( 29, "${basedir}/monthly" ) ) {
                chmod( 0711, "${basedir}/monthly" );
                if ( $CONF{'BACKUPTYPE'} eq "ftp" ) {
                    mkdir( "${basedir}/monthly", 0711 );
                    backupaccts("${basedir}/monthly");
                }
                else {
                    print "[cpbackup] Copying daily backups to monthly backups for retention\n";
                    cpusystem( $rsync_bin, $rsyncopts, "--delete", "${basedir}/daily/", "${basedir}/monthly" );
                }
            }
        }
    }
    Code:
    my $send_message = 0;
    if ( $CONF{'BACKUPINT'} eq "monthly" ) {
        $send_message++;
    
        if ( !-e "${basedir}/monthly" || isolderthen( 29, "${basedir}/monthly" ) ) {
            if ( !-e "${basedir}/monthly" ) {
                mkdir( "${basedir}/monthly", 0711 );
            }
            else {
                chmod( 0711, "${basedir}/monthly" );
            }
    
            backupaccts("${basedir}/monthly");
        }
        else {
            $send_message--;
            print "[cpbackup_dc3] Monthly Backup is up to date.\n";
        }
    }
    
    if ( $CONF{'BACKUPINT'} eq "weekly" ) {
        $send_message++;
    
        if ( $CONF{'BACKUPRETMONTHLY'} && ( !-e "${basedir}/monthly" || isolderthen( 29, "${basedir}/monthly" ) ) ) {
            if ( !-e "${basedir}/monthly" ) {
                mkdir( "${basedir}/monthly", 0711 );
            }
            else {
                chmod( 0711, "${basedir}/monthly" );
            }
    
            backupaccts("${basedir}/monthly");
        }
        elsif ( ( !-e "${basedir}/weekly" || isolderthen( 6, "${basedir}/weekly" ) ) && ( $CONF{'BACKUPRETMONTHLY'} && ( !-e "${basedir}/monthly" && isolderthen( 6, "${basedir}/monthly" ) ) ) ) {
            if ( !-e "${basedir}/weekly" ) {
                mkdir( "${basedir}/weekly", 0711 );
            }
            else {
                chmod( 0711, "${basedir}/weekly" );
            }
    
            backupaccts("${basedir}/weekly");
        }
        else {
            $send_message--;
            print "[cpbackup_dc3] Weekly Backup is up to date.\n";
        }
    }
    
    if ( $CONF{'BACKUPINT'} eq "daily" ) {
        $send_message++;
    
        if ( $CONF{'BACKUPRETMONTHLY'} && ( !-e "${basedir}/monthly" || isolderthen( 29, "${basedir}/monthly" ) ) ) {
            if ( !-e "${basedir}/monthly" ) {
                mkdir( "${basedir}/monthly", 0711 );
            }
            else {
                chmod( 0711, "${basedir}/monthly" );
            }
    
            backupaccts("${basedir}/monthly");
        }
        elsif ( $CONF{'BACKUPRETWEEKLY'} && ( !-e "${basedir}/weekly" || isolderthen( 6, "${basedir}/weekly" ) ) && ( $CONF{'BACKUPRETMONTHLY'} && ( !-e "${basedir}/monthly" && isolderthen( 6, "${basedir}/monthly" ) ) ) ) {
            if ( !-e "${basedir}/weekly" ) {
                mkdir( "${basedir}/weekly", 0711 );
            }
            else {
                chmod( 0711, "${basedir}/weekly" );
            }
    
            backupaccts("${basedir}/weekly");
        }
        elsif ( !-e "${basedir}/daily" || isolderthen( .5, "${basedir}/daily" ) ) {
            if ( !-e "${basedir}/daily" ) {
                mkdir( "${basedir}/daily", 0711 );
            }
            else {
                chmod( 0711, "${basedir}/daily" );
            }
    
            backupaccts("${basedir}/daily");
        }
        else {
            $send_message--;
            print "[cpbackup_dc3] Daily Backup is up to date.\n";
        }
    }
     
Loading...

Share This Page