Well,I have Cpanel. Does anyone know how to backup the entire home directory automatically on the server or to another server and send me a mail notification? Do I need to set up a cron job? Any guidelines? Thanks for your help!
<?php function backup( $username, $password, $hostname, $output = null, $port = 2082 ) { $total = null; if( is_null( $output ) ) $output = basename( $hostname ); $read = fopen( sprintf( 'http://%s:%s@%s:%s/getbackup/backup-%s-%s.tar.gz', $username, $password, $hostname, $port, $hostname, date( "m-d-Y" ) ), 'r' ); if( !$read ) die( sprintf( 'Cannot open %s with username / password combination', $hostname ) ); else print( "Opened connection, starting backup\r\n" ); $write = fopen( $output, 'wb' ); if( !$write ) die( sprintf( 'Cannot open %s for writing', $output ) ); while( !feof( $read ) ): if( !( $written = fwrite( $write, fread( $read, 1024 ) ) ) ) : die( sprintf( 'Cannot write to %s', $output ) ); else : $total += $written; echo "."; endif; endwhile; echo "\r\n"; fclose( $read ); fclose( $write ); return $total ; } if( !( $written = backup( 'un', 'pw', 'hostname', 'backup.tar.gz') ) ): echo "Failed to write backup"; else: echo "Backup complete"; // mail( ) etc endif; ?> PHP: if you choose an output location chmod that location to 777 before execution, if you omit one, then chmod the directory the script is in to 777 want the rest ???
@Joe........do you mean that I need to create a php file......? @agnivo007 .......Not sure what you mean? Are there any other ways of doing this?
yeah it's a php script you can execute as a cron job every X amount of hours.... want rest? I stopped writing theres no point finishing if it's not useful
Yea Joe... I need more info. I created a php file with your code...What to do next? Do I need to change something in the code? Where to place the file? home directory?
you can place the file anywhere on the server you have permission to write to, if you're on shared hosting that's likely to be your ftp/http root. change : // mail( ) etc to mail( 'you@yourdomain.com', 'Backup on ' . date( 'dS F y h:m:s' ), 'wrriten ' . $written . ' bytes' ); then execute the code with cron......
yeh i use the backup functions in WHM to do my site backups, which works great.. and then have a small shell script which copies those backup archives to a remote ftp
If you have access to root whm or your server admin has allowed you access to backup functions then yes you can use whm directly to backup your accounts automatically.
Why not download custom script from cpanel forums? -there are many solutions(scripts) of this problem allready.
http://forums.cpanel.net/ you'll need to register for access, but its an invaluable source for anyone using cpanel/whm