Skip to content

Instantly share code, notes, and snippets.

@marcoskubis
Created June 21, 2018 13:34
Show Gist options
  • Save marcoskubis/70dd5a0fac9d74390e607ff815e79291 to your computer and use it in GitHub Desktop.
Save marcoskubis/70dd5a0fac9d74390e607ff815e79291 to your computer and use it in GitHub Desktop.
Backup database and files of your VPS
<?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