-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.php
More file actions
41 lines (30 loc) · 1.04 KB
/
backup.php
File metadata and controls
41 lines (30 loc) · 1.04 KB
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
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Symfony\Component\Yaml\Yaml;
$config = Yaml::parse(dirname(__FILE__) . "/config.yaml");
$client = S3Client::factory(
[
"key" => $config["aws"]["key"],
"secret" => $config["aws"]["secret"]
]
);
$bucket = $config["aws"]["bucket"];
$path = dirname(__FILE__) . "/";
date_default_timezone_set("Europe/London");
$name = date("G_i_s_d_M_Y");
$databaseUser = $config["database"]["user"];
$databasePassword = $config["database"]["pass"];
$databaseName = $config["database"]["name"];
$databaseHost = $config["database"]["host"];
$assetsPath = $config["assets"];
shell_exec("mysqldump -h $databaseHost -u $databaseUser -p$databasePassword $databaseName > $path$name.sql");
shell_exec("tar -czf $path$name.tar.gz $assetsPath $path$name.sql >/dev/null 2>&1");
$result = $client->putObject(
[
'Bucket' => $bucket,
'Key' => $name . ".tar.gz",
'SourceFile' => $path . $name . ".tar.gz"
]
);
shell_exec("rm $path$name.tar.gz $path$name.sql");