-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbDumpTransfer.php
62 lines (44 loc) · 1.68 KB
/
dbDumpTransfer.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
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once __DIR__ . '/dropbox/helper.php';
use \Dropbox as dbx;
class DbDumpTransfer
{
/**
* this will transfer the dbBackup zip to dropbox(LEAD-140)
*/
public function transferZip()
{
$root_dir = dirname(__DIR__);
$backUpFolderPath = $root_dir . '/api/dbBackUp';
$host = gethostname();
$db_name = 'mydb';
/*dropbox settings starts here*/
$dropbox_config = array(
'key' => 'xxxxxxxx',
'secret' => 'xxxxxxxxx'
);
$appInfo = dbx\AppInfo::loadFromJson($dropbox_config);
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
$accessToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
/*dropbox settings ends here*/
$current_date = date('Y-m-d');
$backUpFileName = $current_date . '_' . $db_name . '.sql.zip';
$fullBackUpPath = $backUpFolderPath . '/' . $backUpFileName;
if (file_exists($backUpFolderPath)) {
$files = scandir($backUpFolderPath); //retrieve all the files
foreach ($files as $file) {
if ($file == $backUpFileName) { // file matches with the db back up file created today
/* transfer the file to dropbox*/
$f = fopen($fullBackUpPath, "rb");
$dbxClient->uploadFileChunked("/$backUpFileName", dbx\WriteMode::add(), $f);
fclose($f);
echo 'Upload Completed';
}
}
}
}
}
$dbTransferObj = new DbDumpTransfer();
$dbTransferObj->transferZip();
?>