Page 1 of 2 12 LastLast
Results 1 to 15 of 18

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

  1. #1
    Member Roy@ENHOST's Avatar
    Join Date
    Mar 2002
    Location
    Los Angeles California
    Posts
    495

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

    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!


    Contents of backup.php

    PHP Code:
    <?
    /****************************
    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
    //********************************

    ?>
    Last edited by Roy@ENHOST; 11-19-2004 at 11:43 AM.
    = = = = = = = = = = = = = = = = = =
    Cpanel XP Evolution (Add DOZENS of functions to your Cpanel NOW!!!) - 21 Languages, User Friendly Interface, Feature Enabled, Highly Customizable, Create Popup Once window, Language Aware, Flash Tutorials, Theme Changer,Integration with Modernbill,WHM AutoPilot,ClientExec,LPanel&WHOISCart

  2. #2
    cPanel Staff cPanelNick's Avatar
    Join Date
    Feb 2003
    Location
    Houston, TX
    Posts
    4,793

    Default

    Quote Originally Posted by Roy@ENHOST
    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!


    Contents of backup.php

    PHP Code:
    <?
    /****************************
    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
    //********************************

    ?>

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

  3. #3
    Member
    Join Date
    Feb 2004
    Posts
    14

    Default

    hehe very nice script !

    now if it was avelable in whm by default would be GREAT !

  4. #4
    Member Roy@ENHOST's Avatar
    Join Date
    Mar 2002
    Location
    Los Angeles California
    Posts
    495

    Default

    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.
    Last edited by Roy@ENHOST; 11-22-2004 at 05:47 PM.
    = = = = = = = = = = = = = = = = = =
    Cpanel XP Evolution (Add DOZENS of functions to your Cpanel NOW!!!) - 21 Languages, User Friendly Interface, Feature Enabled, Highly Customizable, Create Popup Once window, Language Aware, Flash Tutorials, Theme Changer,Integration with Modernbill,WHM AutoPilot,ClientExec,LPanel&WHOISCart

  5. #5
    Member alrock's Avatar
    Join Date
    May 2004
    Posts
    34

    Default

    Thanks Roy for posting this. It works great!

  6. #6
    Member
    Join Date
    Aug 2004
    Posts
    202

    Default

    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 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!
    Last edited by djmerlyn; 11-22-2004 at 11:11 PM.

  7. #7
    Member Roy@ENHOST's Avatar
    Join Date
    Mar 2002
    Location
    Los Angeles California
    Posts
    495

    Default

    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.

    I might release a script to autoinstall MMcache too.
    I am 95% done with it.
    Last edited by Roy@ENHOST; 11-23-2004 at 12:21 AM.
    = = = = = = = = = = = = = = = = = =
    Cpanel XP Evolution (Add DOZENS of functions to your Cpanel NOW!!!) - 21 Languages, User Friendly Interface, Feature Enabled, Highly Customizable, Create Popup Once window, Language Aware, Flash Tutorials, Theme Changer,Integration with Modernbill,WHM AutoPilot,ClientExec,LPanel&WHOISCart

  8. #8
    Member ryno267's Avatar
    Join Date
    Mar 2004
    Location
    Chandler, AZ
    Posts
    214
    cPanel/WHM Access Level

    Root Administrator

    Default

    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. #9
    Member
    Join Date
    Sep 2004
    Location
    U.K.
    Posts
    265

    Default

    i would love to know that as well as i've been building a theme to try stuff out

  10. #10
    Member ryno267's Avatar
    Join Date
    Mar 2004
    Location
    Chandler, AZ
    Posts
    214
    cPanel/WHM Access Level

    Root Administrator

    Default

    Started a new thread cause this is off topic in here....

    http://forums.cpanel.net/showthread.php?t=32399

    thanx

  11. #11
    Member
    Join Date
    Apr 2002
    Posts
    223

    Default

    Back on topic, I think if your adding a "backup now" option please add a "backup now to remote ftp"

  12. #12
    Member
    Join Date
    Aug 2004
    Posts
    202

    Default

    Please add your user auth script before doing anything of the sorts!

    Has anyone run the test posted above? http://forums.cpanel.net/f5/php-script-you-can-use-backup-all-user-accounts-32269.html#post153959

  13. #13
    Member Roy@ENHOST's Avatar
    Join Date
    Mar 2002
    Location
    Los Angeles California
    Posts
    495

    Default

    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.

    Quote Originally Posted by Myacen
    Back on topic, I think if your adding a "backup now" option please add a "backup now to remote ftp"

    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

    Quote Originally Posted by djmerlyn
    Please add your user auth script before doing anything of the sorts!

    Has anyone run the test posted above? http://forums.cpanel.net/showthread.php?p=153959
    What features would you guys like to see in the future version?
    Last edited by Roy@ENHOST; 11-24-2004 at 03:19 AM.
    = = = = = = = = = = = = = = = = = =
    Cpanel XP Evolution (Add DOZENS of functions to your Cpanel NOW!!!) - 21 Languages, User Friendly Interface, Feature Enabled, Highly Customizable, Create Popup Once window, Language Aware, Flash Tutorials, Theme Changer,Integration with Modernbill,WHM AutoPilot,ClientExec,LPanel&WHOISCart

  14. #14
    Member
    Join Date
    Apr 2003
    Location
    New Jersey, USA
    Posts
    414

    Default

    Can this script be edited to save the backups in /backups directory?
    eMax Hosting, LLC - Providing Reliable Hosting Services for the past 3 years
    ¨€ cPanel, MySQL, 24/7 Support, Money Back Guarantee, *Free Website Builder*,
    ¨€ Shared Hosting, Reseller Hosting, Dedicated Management, Site Monitoring Services, 97% Client Rating
    ¨€ Have a Sales Questions? Call us toll free at 1-800-770-eMax!

  15. #15
    Member Roy@ENHOST's Avatar
    Join Date
    Mar 2002
    Location
    Los Angeles California
    Posts
    495

    Default

    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.
    = = = = = = = = = = = = = = = = = =
    Cpanel XP Evolution (Add DOZENS of functions to your Cpanel NOW!!!) - 21 Languages, User Friendly Interface, Feature Enabled, Highly Customizable, Create Popup Once window, Language Aware, Flash Tutorials, Theme Changer,Integration with Modernbill,WHM AutoPilot,ClientExec,LPanel&WHOISCart

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 01-22-2010, 04:53 PM
  2. cPanel / WHM Backup script User
    By egsi in forum New User Questions
    Replies: 1
    Last Post: 11-11-2009, 07:20 PM
  3. Backup script for big accounts
    By AlexAT in forum cPanel & WHM Discussions
    Replies: 4
    Last Post: 04-21-2008, 07:39 AM
  4. Running php script as another user
    By ircmaxell in forum cPanel & WHM Discussions
    Replies: 1
    Last Post: 07-20-2006, 10:33 AM
  5. Replies: 6
    Last Post: 12-31-2003, 06:23 PM