-
Notifications
You must be signed in to change notification settings - Fork 11
/
civicrm_dump.php
35 lines (27 loc) · 1.12 KB
/
civicrm_dump.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
<?php
function civicrm_dump($state) {
$state['start'] = date(DATE_ISO8601);
$tarName = "{$state['project']}." . date('Ymd\THis') . ".tar.gz";
$dumpDir = tempnam('/tmp', 'civicrm_dump_');
// tempnam creates this as a file, so we need to delete it first
`rm $dumpDir`;
`mkdir $dumpDir`;
foreach ($state['databases'] as $name) {
foreach (['USER', 'PASS', 'HOST', 'PORT', 'NAME'] as $var) {
$envVar = strtoupper($name) . '_DB_' . $var;
if (getenv($envVar) === FALSE) {
die("Error: environment variable '$envVar' was not found.\n");
}
$$var = getenv(strtoupper($name) . '_DB_' . $var);
}
`mysqldump -u $USER -p$PASS -h $HOST -P $PORT $NAME --no-tablespaces --single-transaction --skip-triggers | sed -E "/^\/\*\![[:digit:]]+ DEFINER/d" > {$dumpDir}/{$name}.sql`;
}
foreach ($state['directories'] as $name => $path) {
`tar -czf {$dumpDir}/{$name}.tar.gz -C $path .`;
}
$state['end'] = date(DATE_ISO8601);
file_put_contents("$dumpDir/state.json", json_encode($state, JSON_PRETTY_PRINT));
`tar -czf /state/$tarName -C $dumpDir .`;
`rm -r $dumpDir`;
echo "$tarName\n";
}