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.

FTP remote backup 'addon'

Discussion in 'General Discussion' started by Pda0, Sep 24, 2003.

  1. Pda0

    Pda0 Well-Known Member

    Joined:
    Jun 13, 2003
    Messages:
    70
    Likes Received:
    0
    Trophy Points:
    6
    WHM remote backup doesn't backup everything, only accounts. Ive made a script that connects daily to a ftp server of your choice, tars the local daily backup, and uploads it.

    Just in case someone needs it..

    PHP:
    <?php
    // Today
    $date getdate();
    $today $date['year'].$date['mon'].$date['mday'];

    // Config
    $ftp_user_name 'user';
    $ftp_user_pass 'passwd';
    $ftp_server 'ftphost';
    $destination_file "/backup/daily_".$today.".tar";
    $source_file "/tmp/daily_".$today.".tar";

    // Tar
    $out exec("tar cf ".$source_file." /backup/cpbackup/daily");

    // Check everything allright.
    if (!file_exists($source_file))
    {
      echo 
    "Backup tarring failed:".$out
      exit; 
    }

    // set up basic connection
    $conn_id ftp_connect($ftp_server); 

    // login with username and password
    $login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass); 

    // check connection
    if ((!$conn_id) || (!$login_result)) { 
            echo 
    "FTP connection has failed!";
            echo 
    "Attempted to connect to $ftp_server for user $ftp_user_name"
            exit; 
        } else {
            echo 
    "Connected to $ftp_server, for user $ftp_user_name";
        }

    // upload the file
    $upload ftp_put($conn_id$destination_file$source_fileFTP_BINARY); 

    // check upload status
    if (!$upload) { 
            echo 
    "FTP upload has failed!";
        } else {
            echo 
    "Uploaded $source_file to $ftp_server as $destination_file";
        }

    // close the FTP stream 
    ftp_close($conn_id); 

    ?>
    .pd

    cPanel.net Support Ticket Number:

    cPanel.net Support Ticket Number:
     
  2. goodmove

    goodmove Well-Known Member

    Joined:
    May 12, 2003
    Messages:
    624
    Likes Received:
    0
    Trophy Points:
    16
    What would be the code to remove the daily directory on the server once the tar file is transferred to the FTP space?
     
    #2 goodmove, Apr 3, 2004
    Last edited: Apr 3, 2004
  3. Pda0

    Pda0 Well-Known Member

    Joined:
    Jun 13, 2003
    Messages:
    70
    Likes Received:
    0
    Trophy Points:
    6
    Not needed, cpanel automatically rewrites it.

    .pd
     
  4. goodmove

    goodmove Well-Known Member

    Joined:
    May 12, 2003
    Messages:
    624
    Likes Received:
    0
    Trophy Points:
    16
    I know. I would just rather not have all those files lurking in the backup directory.
     
  5. gsbe

    gsbe Active Member

    Joined:
    Jul 27, 2003
    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Nashville, TN
    Could you write a similar script using rsync or rdiff? There is an example in this topic but I need more details to get it running... Thanks for your help.
     
  6. oderland

    oderland Well-Known Member
    PartnerNOC

    Joined:
    Dec 30, 2002
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Kungsbacka, Sweden
    anyone knows how to make backup to second hard drive 1day and second day to remote server (same network) ?

    That would be a greate solution.

    BTW I could not get that backup script to work:
    /usr/local/bin/php -f ftpback.php
    sh: line 1: /tar: No such file or directory

    Any clue?

    Thanks!
     
  7. djblamire

    djblamire Well-Known Member

    Joined:
    May 3, 2003
    Messages:
    250
    Likes Received:
    0
    Trophy Points:
    16
    Does this script work with the incremental backup feature of WHM ???

    Thanks in advance,
    Daniel
     
Loading...

Share This Page