Last active
November 10, 2017 17:33
-
-
Save patpawlowski/f5297bce81c047dc954349b9437b0b00 to your computer and use it in GitHub Desktop.
PHP Script to read a Sugar CRM configuration file, backup the database, and then gzip the backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env php | |
<?php | |
if(!isset($argv[1])){ | |
die("Usage: php getdbbackup.php <path to config.php file>\nExample: php getdbbackup.php ../config.php"); | |
} | |
require $argv[1]; | |
print_r($sugar_config['dbconfig']); | |
$db_host_name = $sugar_config['dbconfig']['db_host_name']; | |
$db_user_name = $sugar_config['dbconfig']['db_user_name']; | |
$db_passwprd = $sugar_config['dbconfig']['db_password']; | |
$db_name = $sugar_config['dbconfig']['db_name']; | |
$backup_date_time = str_replace(':', '_', date(DATE_ATOM)); | |
$filename = "{$db_name}_{$backup_date_time}.sql"; | |
$cmd = "mysqldump -u{$db_user_name} -p{$db_passwprd} -h{$db_host_name} {$db_name} > {$filename}"; | |
echo $cmd.PHP_EOL; | |
exec($cmd); | |
$cmd2 = "gzip {$filename}"; | |
echo $cmd2.PHP_EOL; | |
exec($cmd2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment