-
Notifications
You must be signed in to change notification settings - Fork 1
/
MysqlToDropbox.php
executable file
·50 lines (39 loc) · 1.08 KB
/
MysqlToDropbox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/php -q
<?php
require('Dropbox/autoload.php');
require('BackupClass.php');
//set access token
$token = '';
//project name
$project = 'DropboxBackup/1.0';
//optional, if you want to put backups in different folder
$projectFolder = '';
// location of your temp directory
$tmpDir = "/tmp/";
// username for MySQL
$user = "dbusername";
// password for MySQL
$password = "dbpassword!";
// database name to backup
$dbName = "dbname";
// hostname or IP where database resides
$dbHost = "localhost";
// the zip file will have this prefixed
$prefix = "bu_";
// Create the database backup file
$sqlFile = $tmpDir.$prefix.date('Y_m_d').".sql";
$backupFile = $prefix.date('Y_m_d').".tgz";
$createBackup = "mysqldump -h ".$dbHost." -u ".$user." --password='".$password."' ".$dbName." > ".$sqlFile;
$createZip = "tar cvzPf $backupFile $sqlFile";
exec($createBackup);
exec($createZip);
try {
$bk = new Backup($token,$project,$projectFolder);
$bk->upload($backupFile);
} catch(Exception $e) {
die($e->getMessage());
}
// Delete the temporary files
@unlink($sqlFile);
@unlink($backupFile);
?>