-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Cloud backup restore (#3)
* Implemented Cloud backup restore * Added restorefromfile.sh to README
- Loading branch information
1 parent
2e3a501
commit 698fa12
Showing
4 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
if (!defined('sugarEntry')) { | ||
define('sugarEntry', true); | ||
} | ||
|
||
require_once('config.php'); | ||
if (file_exists('config_override.php')) { | ||
require_once('config_override.php'); | ||
} | ||
|
||
require_once('include/entryPoint.php'); | ||
|
||
echo("Preparing SystemUser...\n"); | ||
$u = \BeanFactory::newBean('Users'); | ||
$GLOBALS['current_user'] = $u->getSystemUser(); | ||
|
||
echo("Running QRR...\n"); | ||
$repair = new \RepairAndClear(); | ||
$repair->repairAndClearAll(['clearAll'], [$mod_strings['LBL_ALL_MODULES']], true, false, ''); | ||
|
||
echo("Rebuilding cache...\n"); | ||
\SugarAutoLoader::buildCache(); | ||
|
||
echo("Warming up Services...\n"); | ||
$sd = new \ServiceDictionary(); | ||
$sd->buildAllDictionaries(); | ||
|
||
echo("Done repairing...\n"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
$sugar_config['full_text_engine']['Elastic']['host'] = 'sugar-elasticsearch'; | ||
$sugar_config['full_text_engine']['Elastic']['port'] = '9200'; | ||
$sugar_config['dbconfig']['db_host_name'] = 'sugar-mysql'; | ||
$sugar_config['dbconfig']['db_user_name'] = 'root'; | ||
$sugar_config['dbconfig']['db_password'] = 'root'; | ||
$sugar_config['dbconfig']['db_name'] = 'sugar'; | ||
$sugar_config['dbconfig']['db_type'] = 'mysql'; | ||
$sugar_config['dbconfig']['db_host_name'] = 'sugar-mysql'; | ||
$sugar_config['external_cache']['redis']['host'] = 'sugar-redis'; | ||
$sugar_config['external_cache_disabled'] = 'false'; | ||
$sugar_config['external_cache_disabled_redis'] = 'false'; | ||
$sugar_config['host_name'] = 'docker.local'; | ||
$sugar_config['site_url'] = 'http://docker.local/sugar'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/bin/bash | ||
|
||
# Rafael Fernandes | ||
# sugarcrm.com | ||
|
||
if [ -z $1 ] | ||
then | ||
echo Provide the backup suffix as script parameters | ||
else | ||
# check if the stack is running | ||
running=`docker ps | grep sugar-mysql | wc -l` | ||
|
||
if [ $running -gt 0 ] | ||
then | ||
# running | ||
now="$(date)" | ||
echo "Starting restore at $now" | ||
|
||
# enter the repo's root directory | ||
REPO="$( dirname ${BASH_SOURCE[0]} )/../" | ||
cd $REPO | ||
|
||
# locate the file | ||
if [ ! -f $1 ] | ||
then | ||
echo $1 does not exist, please provide the tar.gz file path containing the backup to restore | ||
exit 1 | ||
fi | ||
|
||
# if it is our repo, and the source exists, and the destination does not | ||
if [ -f '.gitignore' ] && [ -d 'data' ] | ||
then | ||
echo "Cleaning up previous install (./data/app/sugar) if any, please wait..." | ||
if [ -d 'data/app/sugar' ] | ||
then | ||
rm -rf data/app/sugar | ||
fi | ||
TEMP_FOLDER=./data/app/tmp | ||
if [ -d $TEMP_FOLDER ] | ||
then | ||
rm -rf $TEMP_FOLDER | ||
fi | ||
|
||
mkdir -p "$TEMP_FOLDER/sql" | ||
echo Decompressing $1, please wait... | ||
tar -xf $1 -C $TEMP_FOLDER --strip-components=1 | ||
for f in $TEMP_FOLDER/*.sql; do | ||
mv "$f" "$TEMP_FOLDER/sql/" | ||
done | ||
for f in $TEMP_FOLDER/sugar*; do | ||
mv "$f" $TEMP_FOLDER/sugar | ||
done | ||
|
||
if [ ! -d $TEMP_FOLDER/sugar ] | ||
then | ||
echo \"$TEMP_FOLDER/sugar\" cannot be empty | ||
exit 1 | ||
fi | ||
|
||
if [ -d $TEMP_FOLDER/sql ] | ||
then | ||
find $TEMP_FOLDER/sql -type f -name 'sugar*' ! -name '*triggers*' -exec sh -c 'sql=${1:-:}; x="${2:-:}"; mv "$x" "$sql/sugar.sql"' bash "$TEMP_FOLDER/sql" {} +\; | ||
find $TEMP_FOLDER/sql -type f -name '*triggers*' -exec sh -c 'sql=${1:-:}; x="{}"; mv "${2:-:}" "$sql/sugar_triggers.sql"' bash "$TEMP_FOLDER/sql" {} +\; | ||
fi | ||
|
||
echo Restoring application files | ||
SUGAR_TMP_DIR=`ls -d $TEMP_FOLDER/sugar*` | ||
mv $SUGAR_TMP_DIR ./data/app/sugar | ||
echo Application files restored | ||
|
||
echo Restoring database | ||
docker exec -it sugar-mysql mysqladmin -h localhost -f -u root -proot drop sugar | grep -v "mysqladmin: \[Warning\]" | ||
docker exec -it sugar-mysql mysqladmin -h localhost -u root -proot create sugar | grep -v "mysqladmin: \[Warning\]" | ||
|
||
if [ -f $TEMP_FOLDER/sql/sugar.sql.tgz ] | ||
then | ||
if hash tar 2>/dev/null; then | ||
tar -zxf $TEMP_FOLDER/sql/sugar.sql.tgz | ||
echo Database uncompressed to $TEMP_FOLDER/sql/sugar.sql | ||
fi | ||
fi | ||
|
||
if [ -f $TEMP_FOLDER/sql/sugar.sql ] | ||
then | ||
cat $TEMP_FOLDER/sql/sugar.sql | docker exec -i sugar-mysql mysql -h localhost -u root -proot sugar | ||
if [ -f $TEMP_FOLDER/sql/sugar_triggers.sql ] | ||
then | ||
cat $TEMP_FOLDER/sql/sugar_triggers.sql | docker exec -i sugar-mysql mysql -h localhost -u root -proot sugar | ||
fi | ||
echo Database restored | ||
else | ||
echo Database not found! The selected restore is corrupted | ||
exit 1 | ||
fi | ||
echo "Dockerizing Backup config files..." | ||
sed -i.bak 's@RewriteBase /@RewriteBase /sugar@g' ./data/app/sugar/.htaccess | ||
cat ./utilities/configs/config_override_dockerized.php >> ./data/app/sugar/config_override.php | ||
|
||
echo "Cleaning up please wait..." | ||
if [ -d $TEMP_FOLDER ] | ||
then | ||
rm -rf $TEMP_FOLDER | ||
fi | ||
|
||
# refresh all transient storages | ||
./utilities/build/refreshsystem.sh | ||
|
||
echo Repairing system | ||
cp ./utilities/build/simpleRepair.php ./data/app/sugar | ||
./utilities/runcli.sh "php simpleRepair.php" | ||
echo System repaired | ||
|
||
echo Performing Elasticsearch re-index | ||
./utilities/runcli.sh "./bin/sugarcrm search:silent_reindex --clearData" | ||
echo Restore completed! | ||
fi | ||
now="$(date)" | ||
echo "Restore finished at $now" | ||
else | ||
echo The stack is not running, please start the stack first | ||
fi | ||
fi |