TorrentFlux.com Welcome, Guest. Please login or register.
02-09-2010, 03:19:50
Home Help Search Login Register donate
TorrentFlux Home | TorrentFlux Hosting

+  TorrentFlux Forums
|-+  Code Hacks and Tools
| |-+  TorrentFlux 2.1 Hacks
| | |-+  Backup Database "SQLITE" HACK
« previous next »
Pages: [1] Go Down Print
Author Topic: Backup Database "SQLITE" HACK  (Read 1617 times)
carlo1234
Newbie
*
Offline Offline

Posts: 6



View Profile
« on: 05-12-2006, 18:12:49 »

Hey everybody,

here is a small Hack for Torrentflux to Backup a SQLITE-Database in Torrentflux

For update replace the existing Function backupDatabase() in admin.php:

If've only modify the backupfilename ($file) and add the SQLITE-Command

Code:
//****************************************************************************
// backupDatabase -- backup the database
//****************************************************************************
function backupDatabase()
{
global $cfg;

$file = $cfg["db_name"]."_".$cfg["db_type"]."_".date("Ymd").".tar.gz";
$back_file = $cfg["torrent_file_path"].$file;
$sql_file = $cfg["torrent_file_path"].$cfg["db_name"].".sql";

$sCommand = "";
switch($cfg["db_type"])
{
case "mysql":
$sCommand = "mysqldump -h ".$cfg["db_host"]." -u ".$cfg["db_user"]." --password=".$cfg["db_pass"]." --all -f ".$cfg["db_name"]." > ".$sql_file;
break;
case "sqlite":
$sCommand = "sqlite ".$cfg["db_host"]." .dump > ".$sql_file;
break;
default:
// no support for backup-on-demand.
$sCommand = "";
break;
}

    if($sCommand != "")
    {
        shell_exec($sCommand);
        shell_exec("tar -czvf ".$back_file." ".$sql_file);

        // Get the file size
        $file_size = filesize($back_file);

        // open the file to read
        $fo = fopen($back_file, 'r');
        $fr = fread($fo, $file_size);
        fclose($fo);

        // Set the headers
        header("Content-type: APPLICATION/OCTET-STREAM");
        header("Content-Length: ".$file_size.";");
        header("Content-Disposition: attachement; filename=".$file);

        // send the tar baby
        echo $fr;

        // Cleanup
        shell_exec("rm ".$sql_file);
        shell_exec("rm ".$back_file);
        AuditAction($cfg["constants"]["admin"], _BACKUP_MENU.": ".$file);
    }
}


try it  Smiley

carlo1234
Logged
Pages: [1] Go Up Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by SMF 1.1.1 | SMF © 2006, Simple Machines LLC Powered by PHP