Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

[Script] Give Resellers access to their client's backups

Discussion in 'General Discussion' started by stdout, Nov 26, 2008.

  1. stdout

    stdout Well-Known Member

    Joined:
    Apr 10, 2003
    Messages:
    189
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Nelspruit, Mpumalanga, South Africa
    cPanel Access Level:
    Root Administrator
    Treat your resellers and give them access to their end-user backups!

    Not only will it give them full control over their client's backups, it will also allow them to restore individual files - giving them the ability to more accurately assist their own clients on simply restoration requests.

    The script pulls the backup type (incremental or non-incremental) and also pulls the backup destination. If you are using cPanel's backup system and backing up to secondary - this is the script for you.

    Below is a sample output of the script in action. You can ofcourse set this script to run on a weekly basis to update symlinks.

    If you're running this as a cronjob, be sure to suppress the output with 1> /dev/null
    ie. ~/root/symbackups.pl 1> /dev/null

    Here is the script. Simply Copy/Paste, Chmod and Execute.

    Code:
    #!/usr/bin/perl
    
    chdir("/var/cpanel/users");
    
    my @backups = ("daily","weekly","monthly");
    my $backupdir = `grep BACKUPDIR /etc/cpbackup.conf`;
    my $backuptype = `grep BACKUPINC /etc/cpbackup.conf`;
    
    chomp($backuptype);
    chomp($backupdir);
    
    (undef,$backupdir) = split(/ /,$backupdir);
    (undef,$backuptype) = split(/ /,$backuptype);
    
    my $start_time = time();
    
    if ($backuptype eq "yes") { print "cpbackup set to incremental\n"; $backupinc = 1; }
    elsif ($backuptype eq "no") { print "cpbackup set to non-incremental\n"; $backupinc = 0; }
    else { print "cpbackup not configured!\n"; exit; }
    
    $backupdir .= "/cpbackup";
    print "cpbackup dir set to $backupdir\n";
    
    foreach $backupint (@backups) {
     if (-d "$backupdir/$backupint") { &symbackups(); }
     else { print "$backupdir/$backupint does not exist!\n"; }
    }
    
    my $end_time = time();
    my $runtime = $end_time - $start_time;
    
    print "\ncPanel backup symlink procedure completed in: $runtime seconds\n";
    
    exit;
    
    sub symbackups() {
     print "\nprocessing $backupint backups\n";
    
     open(LIST,"ls -1 |");
      foreach $username (<LIST>) {
       chomp($username);
       $userowner = `grep OWNER $username | cut -d= -f2`;
       chomp($userowner);
       print ".";
       system("mkdir /home/$userowner/backups 2> /dev/null");
       system("chown $userowner:$userowner /home/$userowner/backups 2> /dev/null");
       system("mkdir /home/$userowner/backups/$backupint 2> /dev/null");
       system("chown $userowner:$userowner /home/$userowner/backups/$backupint 2> /dev/null");
    
       if ($backupinc == 1) {
        system("ln -s /backup/cpbackup/$backupint/$username /home/$userowner/backups/$backupint/$username 2> /dev/null");
        system("chown -R :$userowner /backup/cpbackup/$backupint/$username 2> /dev/null");
        system("chmod -R 775 /backup/cpbackup/$backupint/$username 2> /dev/null");
       }
       else {
        system("ln -s /backup/cpbackup/$backupint/$username.tar.gz /home/$userowner/backups/$backupint/$username.tar.gz 2> /dev/null");
        system("chown :$userowner /backup/cpbackup/$backupint/$username.tar.gz 2> /dev/null");
        system("chmod 775 /backup/cpbackup/$backupint/$username.tar.gz 2> /dev/null");
       }
      close(LIST);
     }
    }
    Spot a bug? Let me know! Thanks. I hope this script works out as well
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. rhenderson

    rhenderson Well-Known Member

    Joined:
    Apr 21, 2005
    Messages:
    785
    Likes Received:
    0
    Trophy Points:
    166
    Location:
    Oklahoma
    cPanel Access Level:
    Root Administrator
    Looks like a nice script. Question: Will the linked files count towards the resellers quota?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. stdout

    stdout Well-Known Member

    Joined:
    Apr 10, 2003
    Messages:
    189
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Nelspruit, Mpumalanga, South Africa
    cPanel Access Level:
    Root Administrator
    Nope. It won't.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice