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.

A PHP script that you can use to backup all user accounts

Discussion in 'General Discussion' started by Roy@ENHOST, Nov 19, 2004.

  1. Roy@ENHOST

    Roy@ENHOST Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    495
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Los Angeles California
    Hi guys,

    I recently tried to make backup files of all user accounts.
    I tried using /scripts/cpbackup but it wouldn't let me run because it claimed that my backup files were up to date. I know that they were not.
    Cpanel should have a 'BACKUP ALL ACCOUNTS NOW' function.

    Frustrated, I decided to create a script that scans the homedirectory for user accounts and force Cpanel to create a cpmove backup files in the home directory for each accounts.
    Hope this can come in handy for some of you guys.
    Just upload the php file to /usr/local/cpanel/whostmgr/docroot/ , login to http://IP:2086/backup.php and get the party started!
    :D

    Contents of backup.php

    PHP:
    <?
    /****************************
    Roy
    CPanelskindepot.com
    ****************************/

    //********************************
    //Set time limit so that we don't exceed PHP's maximum execution time.
    //********************************
    set_time_limit (99999999999);
    /***************************/

    //********************************
    //Begin Counter. This way we know how many accounts are going to be backed up
    //********************************
    $i =1;
    /***************************/

    //********************************
    //$noto is just an array of the common non-user directory names.
    //********************************
    $noto = array('.','..','virtfs','cpins','cpzendinstall','cpapachebuild','.cpan','cpphpbuild');
    /***************************/

    //********************************
    //Let's get the party started
    //********************************
    if ($handle opendir('/home')) {

       while (
    false !== ($file readdir($handle))) { 

    if((
    is_dir('/home/'.$file)!==FALSE)&&(!in_array($file,$noto)))
    {

    echo 
    '<b>'.$i.'</b>Backing up: '.$file.'<br><br>';
    echo 
    system('/scripts/pkgacct '.$file);
    echo 
    '<br>';

    $i++;
    }
       }


       
    closedir($handle); 
    }

    //********************************
    //The end of party
    //********************************

    ?>
     
    #1 Roy@ENHOST, Nov 19, 2004
    Last edited: Nov 19, 2004
  2. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider

    You should use getpwent as not all users are always in /home
     
  3. kiko0123

    kiko0123 Member

    Joined:
    Feb 1, 2004
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    hehe very nice script !

    now if it was avelable in whm by default would be GREAT !
     
  4. Roy@ENHOST

    Roy@ENHOST Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    495
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Los Angeles California
    I know that not all the home directories are congifured at /home
    But that was slapped together really quickly for my server as I was frustrated with the lack of 'Backup Now' function. It was originally meant to be for my own use, if you guys wanted to use it, be sure to change the /home to the appropriate directory.

    Anyway I have no idea what getpwent is. Are you referring to Perl?
    I can only do PHP. I have written a function in PHP to detect home directory on a cpanel server but I didn't have the time to integrate it to this backup script yet.
     
    #4 Roy@ENHOST, Nov 22, 2004
    Last edited: Nov 22, 2004
  5. alrock

    alrock Active Member

    Joined:
    May 31, 2004
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Thanks Roy for posting this. It works great! :)
     
  6. djmerlyn

    djmerlyn Well-Known Member

    Joined:
    Aug 31, 2004
    Messages:
    203
    Likes Received:
    1
    Trophy Points:
    16
    I've been doing a little detective work. It is said that PHP can't be run in WHM as a reseller. So, if you folks running this script could perform a little test for us...it would be great~

    Don't get mad at me Roy :p I need to get this figured out for security sake~

    For those of you that have installed this script, could you please perform the following test, and report back the results?

    1. Log in to a customers reseller account. Do not use the root password, use the customers password so that WHM see's you as the reseller and not root.

    2. Try running backup.php as the reseller by adding backup.php to your https://IP:2087, so it looks like this https://IP:2087/backup.php

    3. Answere this question: Does reseller have access to the file? Does the PHP file open and run for the reseller?

    If anyone can try testing this out, and answere if PHP is running from the reseller account...it would be greatly appreciated.

    Also, if the file works as reseller...ensure that you want your resellers to have access to the backup.php file...you might not want them having that kind of access... Especially if 2 or 3 resellers run backup.php at the same time.

    Cheers!
     
    #6 djmerlyn, Nov 22, 2004
    Last edited: Nov 22, 2004
  7. Roy@ENHOST

    Roy@ENHOST Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    495
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Los Angeles California
    To my knowledge and survey of my customer base, the consensus is that you can't run PHP on reseller's WHM(port 2086), so it is safe.
    djmerlyn is the only customer who is able to get it to work.
    I am also curious about this phenomenon.

    Even if you are able to, you only need to add some lines of PHP codes to detect and reject reseller. Easy does it. :cool:

    I might release a script to autoinstall MMcache too. :D
    I am 95% done with it.
     
    #7 Roy@ENHOST, Nov 23, 2004
    Last edited: Nov 23, 2004
  8. ryno267

    ryno267 Well-Known Member

    Joined:
    Mar 3, 2004
    Messages:
    212
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Chandler, AZ
    cPanel Access Level:
    Root Administrator
    This is a nice app - and the directory you posted helps me with another issue...

    But how are you guys uploading files and stuff to your root account on the server? Like I use Putty to SSH in and do stuff but i'm still at a loss of how you upload things to directories.... any secrets would be great... thanks...
     
  9. fusioncroc

    fusioncroc Well-Known Member

    Joined:
    Sep 28, 2004
    Messages:
    261
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    U.K.
    i would love to know that as well as i've been building a theme to try stuff out
     
  10. ryno267

    ryno267 Well-Known Member

    Joined:
    Mar 3, 2004
    Messages:
    212
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Chandler, AZ
    cPanel Access Level:
    Root Administrator
  11. Myacen

    Myacen Well-Known Member

    Joined:
    Apr 6, 2002
    Messages:
    222
    Likes Received:
    0
    Trophy Points:
    16
    Back on topic, I think if your adding a "backup now" option please add a "backup now to remote ftp"
     
  12. djmerlyn

    djmerlyn Well-Known Member

    Joined:
    Aug 31, 2004
    Messages:
    203
    Likes Received:
    1
    Trophy Points:
    16
  13. Roy@ENHOST

    Roy@ENHOST Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    495
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Los Angeles California
    I have added FTP function to the script plus the frontend for users.
    I am now working on the frontend for selective backup so that people can select which accts they want to backup. Also remembering the FTP login info in a 64 bit encrypted string.

    I am also working on the 'DOWNLOAD FROM BACKUP NOW' function.
    You can download from remote FTP and have it automatically restrore accounts.
    Not to forget the selective restore function.

    Will release it on my site pretty soon.
    It's down at the moment. :(


    My server doesn't allow resellers to run PHP on port 2086 by default so I don't need authorization function for that script.
    I guess you can easily drop an .htaccess file to protect it.
    I have no idea why PHP can't run on resellers WHM for most of the servers.
    It baffled me for 6 months already.

    Anyone who can solve this problem get a free 'BACKUP NOW PLUS' and 'RESTORE NOW PLUS'.
    JK :D

    What features would you guys like to see in the future version?
     
    #13 Roy@ENHOST, Nov 24, 2004
    Last edited: Nov 24, 2004
  14. XPerties

    XPerties Well-Known Member

    Joined:
    Apr 10, 2003
    Messages:
    401
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Jersey, USA
    Can this script be edited to save the backups in /backups directory?
     
  15. Roy@ENHOST

    Roy@ENHOST Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    495
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Los Angeles California
    Yeap. That is if I add an extension.
    This is a very simple, generic and flexible script.
    You can pretty much get it to do anything except wash the dishes. :D
     
  16. ryno267

    ryno267 Well-Known Member

    Joined:
    Mar 3, 2004
    Messages:
    212
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Chandler, AZ
    cPanel Access Level:
    Root Administrator
    so do I have this right... you're selling the new backup version script?
     
  17. rizalmhm

    rizalmhm Member

    Joined:
    Jun 24, 2004
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    is very nice if the script can choose which domain we want backup. can it be ?
     
  18. Roy@ENHOST

    Roy@ENHOST Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    495
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Los Angeles California
    Thats a good idea! :D



    Yeah, that's easy. But I didn't have the time to develop that feature yet.

     
Loading...

Share This Page