Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set('Europe/Madrid');
  3. $tipo = $_GET["tipo"];
  4. if (isset($tipo)){
  5.     function upload($file){ //enviamos a telegram
  6.         $bot_id = ""; //ID del bot
  7.         $chat_id_backup = ""; //chat_id al que mandar datos
  8.         $ch = curl_init('https://api.telegram.org/bot' . $bot_id . '/sendDocument?chat_id='.$chat_id_backup);
  9.         $data = array('document' => curl_file_create($file));
  10.         curl_setopt($ch, CURLOPT_POST,1);
  11.         curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:multipart/form-data']);
  12.         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  13.         curl_exec($ch);
  14.     }
  15.     if ($tipo == "SQL"){
  16.         $ruta = ""; //ruta del backup
  17.         $dbhost = "127.0.0.1"; $dbuser = ""; $dbpwd = ""; $dbname = ""; //datos DB
  18.         $dbfile = "db_" . date("Y-m-d_H-i-s") . ".sql"; //nombre archivo
  19.         passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd $dbname > $ruta$dbfile");
  20.         passthru("rm -f $(ls -1t $ruta*.sql | tail -n +50)"); //conservamos los últimos 50 archivos
  21.         upload($ruta.$dbfile);
  22.     }
  23.     if ($tipo == "WEB"){
  24.         $ruta = ""; //ruta del backup sin la carpeta final (podría ser el document_root)
  25.         $carpetabackup = ""; //carpeta específica de los backups
  26.         $webfile = "web_".date("Y-m-d_H-i-s").".tgz";
  27.         shell_exec("tar -cvpzf $ruta/$carpetabackup/$webfile $ruta/* --exclude='$ruta/$carpetabackup' --exclude='$ruta/db_backup' --exclude='$ruta/error*.txt'"); //comprimimos ignorando la carpeta de backup web y db y los logs de error
  28.         passthru("rm -f $(ls -1t $ruta/$carpetabackup/*.tgz | tail -n +10)"); //conservamos los últimos 10 archivos
  29.         upload($ruta."/".$carpetabackup."/".$webfile);
  30.     }
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement