Last active
August 29, 2015 14:21
-
-
Save mindevolution/60f9aa7a2b9f3d1b54a0 to your computer and use it in GitHub Desktop.
bash update discuz portal index
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
#!/bin/bash | |
# first back up the database | |
now=$(date +"%Y-%m-%d_%H:%M") | |
select_mode() | |
{ | |
echo "Select the running mode: | |
1. Local Server | |
2. Production Server | |
" | |
read mode | |
echo "Running Mode is:" | |
if [ "$mode" -eq "1" ]; then | |
host=localhost | |
user=user | |
pw=password | |
db=database | |
echo "Local Server" | |
elif [ "$mode" -eq "2" ]; then | |
host=remotehost | |
user=user | |
pw=password | |
db=database | |
echo "Production Server" | |
else | |
echo "Wrong selecting, exit" | |
exit 1 | |
fi | |
} | |
backup_db() | |
{ | |
select_mode | |
echo "Backup the database" | |
backp_file="docs/db/portal_index_dump_$now.sql" | |
[ -d "docs/db" ] || mkdir -p docs/db | |
echo "Before backup file count: `ls docs/db/ | wc -l`" | |
mysqldump -h$host -u$user -p$pw --databases $db --tables pre_common_template_block > docs/db/pre_common_template_block_$now.sql | |
mysqldump -h$host -u$user -p$pw --databases $db --tables pre_common_diy_data > docs/db/pre_common_diy_data_$now.sql | |
echo "After backup file count: `ls docs/db/ | wc -l`" | |
} | |
update_db() | |
{ | |
echo "Update db..." | |
select_mode | |
sql=' | |
delete from `pre_common_template_block` where `targettplname` = "portal/index"; | |
update `pre_common_template_block` set `targettplname` = "portal/index" where `targettplname` = "portal/index_new"; | |
delete from `pre_common_diy_data` where `targettplname` = "portal/index"; | |
update `pre_common_diy_data` set `targettplname` = "portal/index" where `targettplname` = "portal/index_new"; | |
' | |
mysql -h$host -u$user -p$pw --database $db -e"$sql" | |
echo "Running sql: $sql" | |
} | |
index="template/default/portal/index.htm" | |
index_backup="docs/backup/index.htm.$now.backup" | |
index_new="template/default/portal/index_new.htm" | |
index_tpl="/var/www/koreaxing.com/data/template/1_diy_portal_index.tpl.php" | |
index_tpl_backup="docs/backup/1_diy_portal_index.tpl.php.$now.backup" | |
index_tpl_new="/var/www/koreaxing.com/data/template/1_diy_portal_index_new.tpl.php" | |
update_index() | |
{ | |
echo "Update index..." | |
backup_db | |
update_db | |
# backup the index | |
[ -f $index_backup ] || cp $index $index_backup | |
cp $index_new $index | |
[ -f $index_tpl ] || cp $index_tpl $index_tpl_backup | |
rm $index_tpl | |
cp $index_tpl_new $index_tpl | |
chmod 777 $index_tpl | |
} | |
revert_index() | |
{ | |
echo "Revert index..." | |
# backup the index | |
read -p "Input the index.htm backup file: " index_bakup | |
cp "docs/backup/"$index_bakup $index | |
# cp $index_tpl_backup $index_tpl | |
rm $index_tpl | |
revert_db | |
} | |
revert_db() | |
{ | |
echo "Revert db..." | |
select_mode | |
sql=' | |
drop table `pre_common_template_block`; | |
drop table `pre_common_diy_data`; | |
' | |
mysql -h$host -u$user -p$pw --database $db -e"$sql" | |
read -p "Input the table data pre_common_template_block file: " sql_restore_1 | |
mysql -h$host -u$user -p$pw --database $db < docs/db/$sql_restore_1 | |
read -p "Input the table data pre_common_diy_data file: " sql_restore_2 | |
mysql -h$host -u$user -p$pw --database $db < docs/db/$sql_restore_2 | |
} | |
commands="backup_db update_index revert_index update_db revert_db" | |
select cmd in $commands | |
do | |
if [ ! -z "$cmd" ]; then | |
echo "Your choose option number $REPLY is \"$cmd\"" | |
$cmd | |
else | |
echo "$REPLY is invalid" | |
fi | |
done | |
#backup_db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suppose you replace portal with portal_new template