CPanel – Script Backup Automatico 2011

«
»

Questo script utilizza i CronJob di cPanel per effettuare dei Backup automatici tramite uno script PHP per poi caricarlo su un server FTP specificato.

Cosa sono i CronJob?

I Cron job ti permettono di automatizzare alcuni comandi o script sul tuo server per completare azioni ripetitive automaticamente. Un cron job ti permette di eseguire un certo comando secondo i tempi impostati nel cron job stesso. Ad esempio, potresti impostare un cron job per cancellare i file temporanei ogni settimana così che il tuo spazio disco non si possa riempire o come in questo caso, effettuare dei backup completi automatici.

Lo Script

Lo script originale è stato creato da Justin Cook, mentre questa versione è stata modificata opportunamente per lavorare con le versioni più recenti di cPanel.

La prima cosa che bisogna fare è aprire Notepad o un qualsiasi editor di testo e copiare il codice seguente:

<?php// PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server.
// This script contains passwords. KEEP ACCESS TO THIS FILE SECURE! (place it in your home dir, not /www/)

// ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********

// Info required for cPanel access
$cpuser = “username”; // Username used to login to CPanel
$cppass = “password”; // Password used to login to CPanel
$domain = “domain”; // Domain name where CPanel is run

// Info required for FTP host
$ftpuser = “username@domain.com”; // Username for FTP account
$ftppass = “password”; // Password for FTP account
$ftphost = “ftp.domain.com”; // Full hostname or IP address for FTP host
$ftpmode = “ftp”; // FTP mode (“ftp” for active, “passiveftp” for passive)
$ftpport = “21”;
$rdir = “/”;

// Notification information
$notifyemail = “your@email”; // Email address to send results

// Secure or non-secure mode
$secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP

// Set to 1 to have web page result appear in your cron log
$debug = 0;

// *********** NO CONFIGURATION ITEMS BELOW THIS LINE *********

if ($secure) {
$url = “ssl://”.$domain;
$port = 2083;
} else {
$url = $domain;
$port = 2082;
}

$socket = fsockopen($url,$port);
if (!$socket) { echo “Failed to open socket connection… Bailing out!\n”; exit; }

// Encode authentication string
$authstr = $cpuser.”:”.$cppass;
$pass = base64_encode($authstr);

$params = “dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$rdir&submit=Generate a full backup”;

// Make POST to cPanel
fputs($socket,”POST /frontend/x3/backup/dofullbackup.html?”.$params.” HTTP/1.0\r\n”);
fputs($socket,”Host: $domain\r\n”);
fputs($socket,”Authorization: Basic $pass\r\n”);
fputs($socket,”Connection: Close\r\n”);
fputs($socket,”\r\n”);

// Grab response even if we don’t do anything with it.
while (!feof($socket)) {
$response = fgets($socket,4096);
if ($debug) echo $response;
}

fclose($socket);

?>

Compilare i dettagli elencati spiegati nei commenti (cPanel Access etc.), tranne le impostazioni e la porta FTP. Salvare il file come backup.php e poi caricarlo nella directory principale del server. Attenzione: non caricare questo file nella directory public_html del vostro sito, in quanto contiene nome utente e password che concedono l’accesso a cPanel.

 

Creare un nuovo processo cron andando in cPanel> Cron Job e utilizzare queste impostazioni:

Cronjob1

 

Consigliamo di impostare il tempo di esecuzione : una volta al giorno e di usare il seguente comando:

/usr/local/bin/php /home/username/backup.php

L’impostazione “username” è il vostro nome utente.

Se tutto va bene, il cron verrà eseguito a mezzanotte con le impostazioni che abbiamo usato nell’immagine e il backup sarà caricato come archivio tar.gz nel server remoto. In seguito, per ripristinare il backup effettuato, contattate l’amministratore del server.

 



CPanel – Script Backup Automatico 2011 ultima modifica: 2011-07-30T17:08:13+02:00 da Andrea (Xlogic.org)
1 Comments
  • Ricci says:

    Avevo visitato il sito di Justin Cook, ma essendo del 2006 mi ero accorto da subito che non avrebbe funzionato con il nuovo cpanel.
    Grazie per l’update

    27 Agosto 2011 at 10:22

Lascia un commento

*
*