Advertisement
Guest User

Untitled

a guest
Dec 21st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 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. Connect to db and execute the following query, it will show you all the tables with their size.
  13. ```sql
  14. mysql -h $DB_HOST -u $DB_USER -p$DB_USER_PASSWORD $DB_NAME -e '
  15. SELECT
  16. table_schema as `Database`,
  17. table_name AS `Table`,
  18. round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
  19. FROM information_schema.TABLES
  20. ORDER BY (data_length + index_length) ASC;'
  21. ```
  22. Consider which tables can be skipped, for instance we can ignore data from temporary Magento tables like `%_idx` and `%_tmp`.
  23.  
  24. Then add those tables to the list with option `--ignore-table`, like in the example below
  25. ```bash
  26. (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 \
  27. --ignore-table=$DB_NAME.cache_tag \
  28. --ignore-table=$DB_NAME.sales_bestsellers_aggregated_daily \
  29. --ignore-table=$DB_NAME.core_cache \
  30. --ignore-table=$DB_NAME.magento_logging_event \
  31. --ignore-table=$DB_NAME.magento_logging_event_changes \
  32. --ignore-table=$DB_NAME.customer_log \
  33. --ignore-table=$DB_NAME.report_event \
  34. --ignore-table=$DB_NAME.report_viewed_product_index \
  35. --ignore-table=$DB_NAME.search_query \
  36. --ignore-table=$DB_NAME.url_rewrite \
  37. -h $DB_HOST -u $DB_USER -p$DB_USER_PASSWORD $DB_NAME &) | gzip > /tmp/`date +%s`db.dump.sql.gz
  38. ```
  39.  
  40. ### Declar the following variables with appropriate values, before executing the above command
  41. ```bash
  42. export DB_NAME='magento2_test_db'
  43. export DB_HOST='localhost'
  44. export DB_USER='root'
  45. export DB_USER_PASSWORD='root'
  46. ```
  47.  
  48. After execution you will be able to find dump in the directory `/tmp`
  49. ```bash
  50. ls -laht /tmp/*db.dump.sql.gz
  51. ```
  52. Your dump will be shown at the top of the listed dumps.
  53.  
  54. For applying dumps use the following command
  55. ```bash
  56. 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
  57. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement