Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Code dump
- ```bash
- 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
- ```
- After execution you will be able to find dump in the directory `/tmp`
- ```bash
- ls -laht /tmp/*.code.tar.gz
- ```
- Your dump will be shown at the top of the listed dumps.
- # DB dump
- ### Declar the following variables with appropriate values, before executing the above command
- ```bash
- export DB_NAME='magento2_test_db'
- export DB_HOST='localhost'
- export DB_USER='root'
- export DB_USER_PASSWORD='root'
- ```
- For obtaining the DB credentials, in the Cloud environment, you may use the following command
- ```bash
- echo $MAGENTO_CLOUD_RELATIONSHIPS | base64 --decode | json_pp
- ```
- Execute the following command, it will show you all the tables with their size.
- ```bash
- mysql -h $DB_HOST -u $DB_USER -p$DB_USER_PASSWORD $DB_NAME -e "
- SELECT
- table_schema as \`Database\`,
- table_name AS \`Table\`,
- round(((data_length + index_length) / 1024 / 1024), 2) \`Size in MB\`
- FROM information_schema.TABLES
- WHERE table_schema = '$DB_NAME'
- ORDER BY (data_length + index_length) ASC;
- "
- ```
- Consider which tables can be skipped, for instance we can ignore data from temporary Magento tables like `%_log`, `%_idx` and `%_tmp`.
- Then add those tables to the list with option `--ignore-table`, like in the example below
- ```bash
- (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 \
- --ignore-table=$DB_NAME.cache_tag \
- --ignore-table=$DB_NAME.sales_bestsellers_aggregated_daily \
- --ignore-table=$DB_NAME.core_cache \
- --ignore-table=$DB_NAME.magento_logging_event \
- --ignore-table=$DB_NAME.magento_logging_event_changes \
- --ignore-table=$DB_NAME.customer_log \
- --ignore-table=$DB_NAME.report_event \
- --ignore-table=$DB_NAME.report_viewed_product_index \
- --ignore-table=$DB_NAME.search_query \
- -h $DB_HOST -u $DB_USER -p$DB_USER_PASSWORD $DB_NAME &) | gzip > /tmp/`date +%s`db.dump.sql.gz
- ```
- After execution you will be able to find dump in the directory `/tmp`
- ```bash
- ls -laht /tmp/*db.dump.sql.gz
- ```
- Your dump will be shown at the top of the listed dumps.
- For applying dumps use the following command
- ```bash
- 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
- ```
Add Comment
Please, Sign In to add comment