Last active
November 5, 2016 19:31
-
-
Save diogobaracho/07099922532935ecdae1 to your computer and use it in GitHub Desktop.
Magento common queries: mysqldump , import database, change admin user password, change site url, change cookie domain
This file contains hidden or 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/sh | |
echo "Generate dump?(yes)" | |
read godump | |
if [ $godump = 'yes' ] || [ $godump = 'y' ]; then | |
read -p "mysql user: " YOUR_USER | |
read -p "mysql password: " YOUR_PASSWORD | |
read -p "mysql host: " YOUR_HOST | |
read -p "mysql database: " YOUR_DB | |
read -p "output file: " YOUR_OUTPUT_FILE | |
echo "DUMP ==================================================================================" | |
echo "dumping database.." | |
mysqldump -h $YOUR_HOST -u $YOUR_USER -p$YOUR_PASSWORD --ignore-table=$YOUR_DB.log_customer --ignore-table=$YOUR_DB.log_visitor --ignore-table=$YOUR_DB.log_visitor_info --ignore-table=$YOUR_DB.log_url --ignore-table=$YOUR_DB.log_url_info --ignore-table=$YOUR_DB.log_quote --ignore-table=$YOUR_DB.report_viewed_product_index --ignore-table=$YOUR_DB.report_compared_product_index --ignore-table=$YOUR_DB.report_event --ignore-table=$YOUR_DB.catalog_compare_item --opt $YOUR_DB | gzip > $YOUR_OUTPUT_FILE.sql.gz | |
sed -i 's/DEFINER=[^*]*\*/\*/g' $YOUR_OUTPUT_FILE.sql.gz | |
echo "dump created" | |
echo "--------------------------------------------" | |
echo "Generate tar from dump?(yes)" | |
read choice | |
if [ $choice = 'yes' ] || [ $choice = 'y' ]; then | |
echo "generating tar" | |
tar -czvf YOUR_OUTPUT_FILE.tar.gz $YOUR_OUTPUT_FILE.sql.gz | |
echo "tar created" | |
fi | |
choice=""; | |
fi | |
echo "LOCAL OPTIONS ==================================================================================" | |
echo "Local database changes(import, update site url, change admin user password)?(yes)" | |
read choice | |
if [ $choice = 'yes' ] || [ $choice = 'y' ]; then | |
read -p "mysql user: " user | |
read -p "mysql password: " password | |
read -p "mysql host: " host | |
read -p "mysql database: " database | |
echo "--------------------------------------------" | |
echo "Import to local database from file?(yes)" | |
read choice | |
if [ $choice = 'yes' ] || [ $choice = 'y' ]; then | |
read -p "file to import: " YOUR_OUTPUT_FILE | |
echo "importing database..." | |
#mysql -h $host -u $user -$password -D $database -e "DROP DATABASE IF EXISTS $database;" | |
mysql -h $host -u $user -p$password -e "CREATE DATABASE IF NOT EXISTS $database;" | |
mysql -h $host -u $user -p$password -D $database < $YOUR_OUTPUT_FILE | |
echo "import success" | |
fi | |
choice=""; | |
echo "--------------------------------------------" | |
echo "Update site URLs?(yes)" | |
read choice | |
if [ $choice = 'yes' ] || [ $choice = 'y' ]; then | |
read -p "new site url: " local_url | |
echo "updating..." | |
mysql -h $host -u $user -p$password -D $database -e "update core_config_data set value = '$local_url' where path = 'web/unsecure/base_url'"; | |
mysql -h $host -u $user -p$password -D $database -e "update core_config_data set value = '$local_url' where path = 'web/secure/base_url'"; | |
echo "done" | |
fi | |
choice=""; | |
echo "--------------------------------------------" | |
echo "Update cookie domain?(yes)" | |
read choice | |
if [ $choice = 'yes' ] || [ $choice = 'y' ]; then | |
read -p "cookie domain: " local_url | |
echo "updating..." | |
mysql -h $host -u$user -p$password -D $database -e "update core_config_data set value='$local_url' where path='web/cookie/cookie_path' and value is not null"; | |
echo "done" | |
fi | |
choice=""; | |
echo "--------------------------------------------" | |
echo "Change admin user password?(yes)" | |
read choice | |
if [ $choice = 'yes' ] || [ $choice = 'y' ]; then | |
read -p "user name: " user_name | |
read -p "new password: " new_password | |
echo "updating..." | |
mysql -h$host -u$user -p$password -D$database -e "UPDATE admin_user SET password = MD5('$new_password') WHERE username = '$user_name'"; | |
echo "done" | |
fi | |
choice=""; | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment