Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set('Europe/Madrid');
  3.  
  4. $bot_id = "";
  5. $chat_id_backup = ""; //chat_id al que mandar datos
  6. $ruta = "/var/www/..."; //ruta del backup
  7. $dbhost   = "127.0.0.1"; $dbuser = ""; $dbpwd = ""; $dbname = "";
  8. $dumpfile = $dbname . "_" . date("Y-m-d_H-i-s") . ".sql";
  9.  
  10. passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd $dbname > $ruta$dumpfile"); //Genera el backup
  11. passthru("rm -f $(ls -1t $ruta*.sql | tail -n +50)"); //Borrar todas las copias menos las últimas 50
  12.  
  13. //Enviamos backup generado a chat_id
  14. $ch = curl_init('https://api.telegram.org/bot' . $bot_id . '/sendDocument?chat_id='.$chat_id_backup);
  15. $data = array('document' => curl_file_create($ruta.$dumpfile));
  16. curl_setopt($ch, CURLOPT_POST,1);
  17. curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:multipart/form-data']);
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  19. curl_exec($ch);
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement