Created
June 21, 2018 13:34
-
-
Save marcoskubis/70dd5a0fac9d74390e607ff815e79291 to your computer and use it in GitHub Desktop.
Backup database and files of your VPS
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 | |
$destination = "/home/user/backups"; | |
$filename = "db_backup.sql"; | |
$host = '127.0.0.1'; | |
$database = 'mydb'; | |
$password = 'mypass'; | |
$gdrive_folder = '0B2WMB4jNcJeRVTd6TTliZWVVSFE'; | |
// Dumps mysql database to a sql file called "db_backup.sql" | |
system("mysqldump -h {$host} -u {$database} -p{$password} --databases {$database} > {$destination}/{$filename}"); | |
// Zip the sql file | |
system("cd {$destination} && zip {$filename}.zip {$filename}"); | |
// For many files | |
// system("zip -r folder_name.zip folder_name"); | |
// Remove sql file | |
system("rm {$destination}/{$filename}"); | |
// Sends the zipped file to google drive | |
// Requirement: https://github.com/prasmussen/gdrive | |
system("/usr/local/bin/gdrive sync upload --delete-extraneous --keep-local {$destination} {$gdrive_folder}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment