Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('Europe/Madrid');
- $tipo = $_GET["tipo"];
- if (isset($tipo)){
- function upload($file){ //enviamos a telegram
- $bot_id = ""; //ID del bot
- $chat_id_backup = ""; //chat_id al que mandar datos
- $ch = curl_init('https://api.telegram.org/bot' . $bot_id . '/sendDocument?chat_id='.$chat_id_backup);
- $data = array('document' => curl_file_create($file));
- curl_setopt($ch, CURLOPT_POST,1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:multipart/form-data']);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_exec($ch);
- }
- if ($tipo == "SQL"){
- $ruta = ""; //ruta del backup
- $dbhost = "127.0.0.1"; $dbuser = ""; $dbpwd = ""; $dbname = ""; //datos DB
- $dbfile = "db_" . date("Y-m-d_H-i-s") . ".sql"; //nombre archivo
- passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd $dbname > $ruta$dbfile");
- passthru("rm -f $(ls -1t $ruta*.sql | tail -n +50)"); //conservamos los últimos 50 archivos
- upload($ruta.$dbfile);
- }
- if ($tipo == "WEB"){
- $ruta = ""; //ruta del backup sin la carpeta final (podría ser el document_root)
- $carpetabackup = ""; //carpeta específica de los backups
- $webfile = "web_".date("Y-m-d_H-i-s").".tgz";
- 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
- passthru("rm -f $(ls -1t $ruta/$carpetabackup/*.tgz | tail -n +10)"); //conservamos los últimos 10 archivos
- upload($ruta."/".$carpetabackup."/".$webfile);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement