PHP - Php Makeing A Backup
Ok. I managed to do something like this:
I used CreateZipFile classs from php classes! Code: [Select] <?php include_once 'CreateZipFile.inc.php'; $createZip = new CreateZipFile; $createZip->zipDirectory('binary', ''); $zipFileName = 'backup.zip'; $handle = fopen($zipFileName, 'wb'); $out = fwrite($handle, $createZip->getZippedFile()); fclose($handle); $createZip->forceDownload($zipFileName); @unlink($zipFileName); ?> but there is still one small issue. The archive doesn't contain any empty folders within the binary folder. Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=352495.0 Hello all, I need to be able to create file backups on different types of servers running php (windows or linux). I was hoping that there was a good php class out there that would already handle this for me but I have not come across anything as of yet. I can do it perfectly fine in the linux environment but was hoping to find something that would work on a variety of servers running php. I was hoping that it would support php 4 for older sites. If anyone has any good resources for this please let me know. Thanks hi, im looking for a way to make a page that will backup my mysql when i click a button and i can save it locally on any machine i use. anybody able to help me out with what to search in google? thanks! I am using small script (with crone) to backup database every morning, zip and send me mail (with .sql/zip attached). But backup is not in UTF-8 format, so I get this: "Č" -> "C" "Š" -> "S" etc. I have tried various solution but nothing works. Also tried utf_encode() function, but then I get strange characters. Script looks like this: function backup_tables($host,$user,$pass,$name,$tables = '*',$date) { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //ALL TABLES if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //GET DATA foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE IF EXISTS '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = str_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //SAVE $handle = fopen('Backup-'.$date.'.sql','w+'); fwrite($handle,$return); fclose($handle); } Database Collation: utf8_binType: [/size]MyISAM [/size]How to save .sql file in proper UTF-8 Format?[/b][/size][/font] Hi This is a really basic question but i am trying to understand the process of uploading to amazon S3, I dont want to just download a pre-wriiten script that i dont understand whats happen. I am using the s3.php class require_once('S3.php'); $s3 = new S3('[EDITED]', '[EDITED]'); $ourFileName = "files/test.txt"; $ourFileHandle = fopen($ourFileName, 'r') or die("can't open file"); fclose($ourFileHandle); if ($s3->putObjectFile("files/test.txt", "mybucket", "test/test.txt", S3::ACL_PUBLIC_READ)) { echo "<strong>We successfully uploaded your file.</strong>"; }else{ echo "<strong>Something went wrong while uploading your file... sorry.</strong>"; } Ok so i am just doing this to figure it out, so i create a file and then upload to amazon s3 this works fine, where i am confused is when you backup all files and directories in a site, i dont want all the backup files in the root off my website i want them to automatically upload to amazon. So how does the process work? if i upload a file it works great but i am still upload a file form my server. How does amazon automatically grab files from my server and upload them. Anyone no any basic step by step tutorials i have googled loads but they are all massive pre written classes and stuff which i can get working, but looking for a basic example. Thanks I have been searching the web and I can't fond anyone that has working code for backing up database with PHP. Most of them have the notorious depreciated ereg_replace function. Does anyone know of a simple solution? I want it to backup all the tables in the database How would I go about using PHP to export all the data in my SQL database to a .sql file? Also how can I then import that .sql file back into the database? Thanks! I looked into this everywhere,but the code does not make sense, is not properly documented and is outdated. Ive been trying to achieve this for the past hour. Anybody know how I can do this? This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314405.0 Can we create a backup of database entered data in PHPMYADMIN? As you know if we are using locally any database through php then in case of system crash or the like our all the enterred saved data in the database will gonna be lost i want to know that is it possible to create a back up for our saved data in the database and if is it possible then how can we do it???? Hi, I have a some online backup software call ahsay, I' am looing to create a API call with a form in PHP Please check out this link www.123-backup.com/obs-admin-guide.pdf this is the guide to create a api for the online backup (page 69) Would some be intrested in creating this api call and php form for me ? p.s please see attached image this is something i'am looking for. if so how much would it be please email me if you want more info! hi all i am looking for the quickest way to zip all files and folder of a website i am currently using the followning. <?php $date = date("F-j-Y-g-ia"); if(exec("cd /home/isd/public_html/bk/files;tar -cvpzf backup-$date.tar /home/isd/public_html")) { echo "done"; } ?> This works but was just wondering if anyone can give me and insight on a better solution?? Thanks Here is function that backup mysql database. It's working fine, but I want to download file instead of creating it. /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = '*') { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //get all of the tables if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = str_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $date= date("d-M-Y_h-i"); $handle = fopen('Backup-'.$date.'.sql','w+'); fwrite($handle,$return); fclose($handle); } Usage: Quote backup_tables('HOST','USER','PASS','TABLE'); But this will create backup file on server. I also tried to add following code in function (at the end): echo $return; header('Content-type: text/plain'); header("Content-Disposition: attachment; filename=\"$filename\""); How to just download file, without showing it on screen instead of using fwrite/fclose function? |