The new Cpanel backup system loses backups of accounts that are terminated, which is horrible. Many times I've had customers come back to our hosting just because we hold that dear and valuable backup, so losing backups of terminated accounts for us is a no-no.
Here is a script I wrote to find out which backups out there in /backup/YYYY-MM-DD and /backup/monthly/YYYY-MM-DD that are not active anymore, that were terminated and need to be archived. I don't do weeklys in this server, and are not taken into account.
Script is read-only and its purpose is to display the cp commands that you can review and shell in. Script does not write files or copy files. It only reads and reports what should be done to archive.
Place in a file, chmod u+x, run. Look at the output. Shell output if you like it. Mkdir /backup/arc beforehand.
Disclaimer: Use at your own risk. Feel free to point me to a better way of doing this. Maybe Cpanel should have a check mark in Backup Config to say "Retain deleted accounts? YES. Then a choice: Keep newest or oldest backup? Newest. That.
THANKS TO THE CPANEL FORUM AND COMMUNITY THAT HAS SAVED ME A THOUSAND TIMES.
SUBJECT: BACKUP RETENTION OF TERMINATED ACCOUNTS
Here is a script I wrote to find out which backups out there in /backup/YYYY-MM-DD and /backup/monthly/YYYY-MM-DD that are not active anymore, that were terminated and need to be archived. I don't do weeklys in this server, and are not taken into account.
Script is read-only and its purpose is to display the cp commands that you can review and shell in. Script does not write files or copy files. It only reads and reports what should be done to archive.
Place in a file, chmod u+x, run. Look at the output. Shell output if you like it. Mkdir /backup/arc beforehand.
Disclaimer: Use at your own risk. Feel free to point me to a better way of doing this. Maybe Cpanel should have a check mark in Backup Config to say "Retain deleted accounts? YES. Then a choice: Keep newest or oldest backup? Newest. That.
Code:
#!/usr/local/bin/perl
open(INF,"</etc/trueuserdomains") || die "cannot open /etc/trueuserdomains\n";
@lines = <INF>;
close(INF);
chomp(@lines);
foreach $line (@lines){
@cells = split(/\:\ /,$line);
if(@cells == 2){
$tgzname = $cells[-1].".tar.gz";
$tgzdomain = $cells[0];
$tgzisactiveh{$tgzname} = $cells[0];
}
}
@dailybranches = `find /backup/* -maxdepth 0 -type d`;
@dailybranches = sort { $a <=> $b } @dailybranches;
@dailybranches = grep(/[0-9]{4}-[0-9]{2}-[0-9]{2}$/,@dailybranches);
chomp(@dailybranches);
@monthlybranches = `find /backup/monthly/* -maxdepth 0 -type d`;
@monthlybranches = sort { $a <=> $b } @monthlybranches;
@monthlybranches = grep(/[0-9]{4}-[0-9]{2}-[0-9]{2}$/,@monthlybranches);
chomp(@monthlybranches);
@branches = ();
push(@branches,@dailybranches);
push(@branches,@monthlybranches);
foreach $branch (@branches){
@cells = split(/\//,$branch);
@cells = grep(/[0-9]{4}-[0-9]{2}-[0-9]{2}/,@cells);
$branchdate = $cells[0];
$branchdateh{$branchdate} = $branch;
$branch = $branch . '/accounts';
}
@branchdates = keys(%branchdateh);
@branchdates = sort { $a <=> $b } @branchdates;
@files = ();
foreach $branch (@branches){
@morefiles = `find $branch/*.tar.gz`;
chomp(@morefiles);
push(@files,@morefiles);
}
foreach $file (@files){
@cells = split(/\//,$file);
$tgzname = $cells[-1];
@cells = grep(/[0-9]{4}-[0-9]{2}-[0-9]{2}/,@cells);
$cell = $cells[0];
$tgzdate = $cell;
if(!exists($tgzdateh{$tgzname})){
$tgzdateh{$tgzname} = $tgzdate;
}
else{
$tgzdateh{$tgzname} = $tgzdateh{$tgzname}."|".$tgzdate;
}
$tgznamedate = $tgzname."|".$tgzdate;
$tgznamedatefileh{$tgznamedate} = $file;
}
@tgznames = keys %tgzdateh;
@tgznames = sort(@tgznames);
@tgztakes = ();
foreach $tgzname (@tgznames){
if(!exists($tgzisactiveh{$tgzname})){
$tgzwhat = $tgzdateh{$tgzname};
print "tgzname=$tgzname tgzwhat=$tgzwhat\n";
@tgzdates = split(/\|/,$tgzwhat);
@tgzdates = sort { $a <=> $b } @tgzdates;
$tgzdate = $tgzdates[0];
$tgznamedate = $tgzname."|".$tgzdate;
$tgzfile = $tgznamedatefileh{$tgznamedate};
print " take $tgzfile\n";
push(@tgztakes,$tgzfile);
}
}
foreach $tgztake (@tgztakes){
print "cp -fp $tgztake /backup/arc\n";
}
print "TAKE THESE NEWEST BACKUPS FOR DELETED ACCOUNTS!\n";
THANKS TO THE CPANEL FORUM AND COMMUNITY THAT HAS SAVED ME A THOUSAND TIMES.
SUBJECT: BACKUP RETENTION OF TERMINATED ACCOUNTS
Last edited by a moderator: