Help - Search - Members - Calendar
Full Version: Suggestions for modifying "/scripts/cpbackup" .. please??
The Planet Forums > Control Panels > cPanel/WHM
Web4U
Hi all!

I'm using the bundled cPanel backup script to backup my sites to a different server via FTP. The script works great, except that I have one site which is used for backup of another server, so obviously I don't want to perform a backup of that backup (due to size and redundancy).

I have edited a different backup script (written in PHP) which I use on my Ensim servers, adding a line as such:
[PHP]if ($domain == "ignore.this.domain") return;[/PHP] this single line does exactly what I want (i.e. skip a single site I don't want to backup).

That's fine and dandy since the script I modified is written in PHP, but I honestly don't have a clue about Perl coding. SO, I'm hoping that anyone who knows Perl can help me with this. The snippet below is from the cPanel backup script and is the subroutine which I think all the backup action takes place.

Can somebody please help me and provide a piece of code that does the same effect as the above PHP code? All I know is that cPanel "sites" are actually "users" in the /home dir, but I don't understand any of the following code....

* the following is in PERL *
[PHP]sub backupaccts {
my($target) = @_;

system("touch","${target}");
#if another cpbackup starts just go bye bye

if (!($CONF{'BACKUPFILES'} eq "no")) {
if (! -e "$target/files") {
mkdir("$target/files",0700);
}
my($file);
foreach $file (@FILES) {
next if (! -e $file);
my $rawfile = $file;
$rawfile =~ s///_/g;
if ($CONF{'BACKUPINC'} eq "yes") {
cpusystem("rsync","-a","--delete","$file","$target/files/$rawfile");
} else {
cpusystem("cp","-f","$file","$target/files/$rawfile");
chmod(0600,"$target/files/$rawfile");
cpusystem("gzip","-f","$target/files/$rawfile");
chmod(0600,"$target/files/$rawfile.gz");
}
}
my($file);
if (! -e "$target/dirs") {
mkdir("$target/dirs",0700);
}
foreach $dir (@DIRS) {
next if (! -e $dir);
my $rawdir = $dir;
$rawdir =~ s///_/g;
if ($CONF{'BACKUPINC'} eq "yes") {
cpusystem("rsync","-a","--delete","$dir/","$target/dirs/$rawdir");
} else {
cpusystem("tar","cfzp","$target/dirs/$rawdir.tar.gz","$dir");
chmod(0600,"$target/dirs/$rawdir.tar.gz");
}
}
}[/PHP]
Please help!! :confused:

p/s - maybe this is not even the correct bit of code to edit ...... I don't know, I told you I can't read Perl!!
Web4U
OK...

I decided to "study" the script myself and use GOOGLE to find out what was going on. Finally, found a way to make the script skip a single user. The small edit is towards the end of the file (the subroutine I mentioned in my previous post was not the one!!) icon_biggrin.gif hehe

Here is the original code:[PHP]if (!($CONF{'BACKUPACCTS'} eq "no")) {
while($user = getpwent()) {
if (-f "/var/cpanel/users/${user}") {
if (!($CONF{'BACKUPINC'} eq "yes")) { if (-d "$target/${user}") { cpusystem("rm","-rf","$target/${$
if ($CONF{'BACKUPINC'} eq "yes") { $ENV{'INCBACKUP'} = 1; }
cpusystem("/scripts/pkgacct2",$user,$target,"backup");
if ($CONF{'BACKUPINC'} eq "yes") { delete $ENV{'INCBACKUP'}; }
if($CONF{'BACKUPTYPE'} eq "ftp") {
ftpsend("$target","${target}/${user}.tar.gz","${user}.tar.gz");
unlink("${target}/${user}.tar.gz");
}
}
}
}[/PHP]

And here it is after the small modification:[PHP]if (!($CONF{'BACKUPACCTS'} eq "no")) {
while($user = getpwent()) {
if (-f "/var/cpanel/users/${user}") {
if (!(${user} eq "backup")) {
if (!($CONF{'BACKUPINC'} eq "yes")) { if (-d "$target/${user}") { cpusystem("rm","-rf","$t$
if ($CONF{'BACKUPINC'} eq "yes") { $ENV{'INCBACKUP'} = 1; }
cpusystem("/scripts/pkgacct",$user,$target,"backup");
if ($CONF{'BACKUPINC'} eq "yes") { delete $ENV{'INCBACKUP'}; }
if($CONF{'BACKUPTYPE'} eq "ftp") {
ftpsend("$target","${target}/${user}.tar.gz","${user}.tar.gz");
unlink("${target}/${user}.tar.gz");
}
}
}
}
}[/PHP]

Basically, an extra if statement to check whether the current user is = backup. Actually, it checks if the user is NOT backup and then proceeds with the backup. Of course, you'll have to replace the user name you want to skip!

Hope this is useful to somebody icon_wink.gif
Gilgamesh
Excellent thanks! icon_biggrin.gif

has halved both sys load at backup time and bandwidth usage overall... *phew*

(will be overwritten with cpanel updates back to the default cpbackup) icon_wink.gif
gochris
Since my server is setup to auto updates...my edit to this script gets overwritten all the time.

Is there anyway to fix this, or to have the backup skip a site?
Jeewhizz
QUOTE
Originally posted by gochris
Since my server is setup to auto updates...my edit to this script gets overwritten all the time.

Is there anyway to fix this, or to have the backup skip a site?


type chattr +i /scripts/cpbackup

which will lock it..

Jee
gochris
thanks, I hoping they dont update the backup script too often.

but i'll just try and manually update it once in a while.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.