Last active
April 25, 2016 14:22
-
-
Save diegargon/5cc0965be5d5a9f2d2a53e6ad1ac5d5f to your computer and use it in GitHub Desktop.
Simple php script for backup a database and upload to dropbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* diegargon http/mail: diego.envigo.net | |
* Simple php script for backup a database and upload to dropbox | |
* This script need Dropbox_Uploader https://github.com/andreafabrizi/Dropbox-Uploader | |
* Warning: zip/password its a bad option if you want protect sensitive data | |
*/ | |
// Config Start | |
$tmp_dir = "/tmp/"; | |
$db_user = ""; | |
$db_password = ""; | |
$db_name = ""; | |
$db_host = "localhost"; | |
$date = date('d_m_Y'); | |
$prefix = "db.$db_name.$date"; | |
$dropbox_dest = ""; //Folder | |
$zip_password = ""; | |
$uploader_path = "dropbox_uploader.sh"; //Path to dropbox_uploader | |
// End config | |
$sql_file = $tmp_dir.$prefix.".sql"; | |
$backup_file_tar = $tmp_dir.$prefix.".tar"; | |
$backup_file_zipped = $tmp_dir.$prefix.".tgz"; | |
exec ("mysqldump -h ".$db_host." -u ".$db_user." --password='".$db_password."' ".$db_name." --> ".$sql_file); | |
exec("tar cvf $backup_file_tar $sql_file 2> /dev/null"); | |
exec("zip -P $zip_password -r $backup_file_zipped $backup_file_tar"); | |
exec("$uploader_path upload $backup_file_zipped $dropbox_dest/$prefix.tgz"); | |
unlink($sql_file); | |
unlink($backup_file_zipped); | |
unlink($backup_file_tar); | |
echo "Successful uploading the $db_name backup to $dropbox_dest/$prefix.tgz"; | |
exit(0); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment