Guest User

Untitled

a guest
Jan 3rd, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. # Code dump
  2. ```bash
  3. tar cf - ./ --exclude=pub/media/catalog/* --exclude=pub/media/* --exclude=pub/media/backup/* --exclude=pub/media/import/* --exclude=pub/media/tmp/* --exclude=pub/static/* --exclude=var/* --exclude=private --exclude=tests | gzip > /tmp/`date +%s`.code.tar.gz
  4. ```
  5. After execution you will be able to find dump in the directory `/tmp`
  6. ```bash
  7. ls -laht /tmp/*.code.tar.gz
  8. ```
  9. Your dump will be shown at the top of the listed dumps.
  10.  
  11. # DB dump
  12.  
  13. ### Declar the following variables with appropriate values, before executing the above command
  14. ```bash
  15. export DB_NAME='magento2_test_db'
  16. export DB_HOST='localhost'
  17. export DB_USER='root'
  18. export DB_USER_PASSWORD='root'
  19. ```
  20.  
  21. For obtaining the DB credentials, in the Cloud environment, you may use the following command
  22. ```bash
  23. echo $MAGENTO_CLOUD_RELATIONSHIPS | base64 --decode | json_pp
  24. ```
  25.  
  26. Execute the following command, it will show you all the tables with their size.
  27. ```bash
  28. mysql -h $DB_HOST -u $DB_USER -p$DB_USER_PASSWORD $DB_NAME -e "
  29. SELECT
  30. table_schema as \`Database\`,
  31. table_name AS \`Table\`,
  32. round(((data_length + index_length) / 1024 / 1024), 2) \`Size in MB\`
  33. FROM information_schema.TABLES
  34. WHERE table_schema = '$DB_NAME'
  35. ORDER BY (data_length + index_length) ASC;
  36. "
  37. ```
  38. Consider which tables can be skipped, for instance we can ignore data from temporary Magento tables like `%_log`, `%_idx` and `%_tmp`.
  39.  
  40. Then add those tables to the list with option `--ignore-table`, like in the example below
  41. ```bash
  42. (mysqldump --no_data --routines --force --skip-opt --single-transaction --create-options --disable-keys --extended-insert --set-charset --quick --add-drop-table -h $DB_HOST -u $DB_USER -p$DB_USER_PASSWORD $DB_NAME | sed -e 's/DEFINER[ ]*=[ ]*[Backup dumps without backup.sh script^*]*\*/\*/' && mysqldump --force --skip-opt --skip-add-drop-table --no-create-info --skip-triggers --single-transaction --quick \
  43. --ignore-table=$DB_NAME.cache_tag \
  44. --ignore-table=$DB_NAME.sales_bestsellers_aggregated_daily \
  45. --ignore-table=$DB_NAME.core_cache \
  46. --ignore-table=$DB_NAME.magento_logging_event \
  47. --ignore-table=$DB_NAME.magento_logging_event_changes \
  48. --ignore-table=$DB_NAME.customer_log \
  49. --ignore-table=$DB_NAME.report_event \
  50. --ignore-table=$DB_NAME.report_viewed_product_index \
  51. --ignore-table=$DB_NAME.search_query \
  52. -h $DB_HOST -u $DB_USER -p$DB_USER_PASSWORD $DB_NAME &) | gzip > /tmp/`date +%s`db.dump.sql.gz
  53. ```
  54.  
  55. After execution you will be able to find dump in the directory `/tmp`
  56. ```bash
  57. ls -laht /tmp/*db.dump.sql.gz
  58. ```
  59. Your dump will be shown at the top of the listed dumps.
  60.  
  61. For applying dumps use the following command
  62. ```bash
  63. gunzip -cf "/tmp/1482311063db.dump.sql.gz" | gunzip -cf | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | grep -v 'mysqldump: Couldn.t find table' | grep -v 'Warning: Using a password' | mysql -u $DB_USER --password=$DB_USER_PASSWORD -h $DB_HOST --force $DB_NAME
  64. ```
Add Comment
Please, Sign In to add comment