PHP Script - Backup MYSQL and password protect the zip file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

PHP Script - Backup MYSQL and password protect the zip file

Post by davidhopkins »

Hello All.

I am trying to write a PHP Script that when called allows me to backup a database, put the contents into a zipped folder which is saved to the server and also allow the user to download the file. I have all this working fine, there are no problems at all.

My problem comes thou when i try to password protect this zipped folder. I dont want just anybody to be able to download it and use it. I would like to add a passoword to the folder in the php script, but im unsure on how to do this, any suggestions ?

Here is my code

Code: Select all

<?php

ini_set("memory_limit","40M");

$dbhost = "localhost";
$dbuser = "dbname";
$dbpass = "pw";
$dbname = "dbuser";

$backupfile = $dbname . date("Y-m-d") . '.sql';
$backupzip = $backupfile . '.tar.gz';
echo    "Backup file created. File name is -  "   ;
system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile");
system("tar -czvf $backupzip $backupfile");

header("Location: $backupzip");

unlink($backupfile);

?>
Thanks in advance

David
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Re: PHP Script - Backup MYSQL and password protect the zip f

Post by davidhopkins »

Is anybody able to help with this ? Ive been looking on the net got two days now with no real luck =[
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Script - Backup MYSQL and password protect the zip f

Post by Celauran »

The functionality isn't built into tar, so you'll need to add an extra step. You could try pgp or crypt.
zaster79
Forum Newbie
Posts: 7
Joined: Tue Nov 16, 2010 9:37 am

Re: PHP Script - Backup MYSQL and password protect the zip f

Post by zaster79 »

Don't know if this will help you or not...but found it a paid for forum site.

Code: Select all

<?php

system('zip -P yourpassword destinationfile.zip filetobezipped.sql');

?>
Obviously you are using tar not zip, if it is installed on your server the above might be a solution.

http://www.info-zip.org/
Post Reply