{"id":132277,"date":"2018-08-22T00:07:43","date_gmt":"2018-08-22T00:07:43","guid":{"rendered":"http:\/\/inchoo.net\/?p=32436"},"modified":"2018-08-22T00:07:43","modified_gmt":"2018-08-22T00:07:43","slug":"gdpr-compliant-magento-2-database-dump","status":"publish","type":"post","link":"https:\/\/www.sushilkumar.ind.in\/blog\/php\/gdpr-compliant-magento-2-database-dump\/","title":{"rendered":"GDPR compliant Magento 2 database dump"},"content":{"rendered":"<p>On May 25th, a data privacy law known as GDPR came into effect. It impacts the way companies collect and handle user data. In this article we will show you how to handle personal user data when creating database dumps in order to avoid potential GDPR penalties.<span id=\"more-32436\"><\/span><\/p>\n<h2>What is GDPR?<\/h2>\n<p>In short, General Data Protection Regulation or GDPR is a set of rules that regulate how EU citizen data must be managed, empowering EU citizens with more control over their personal data. Organizations have to make sure that personal data is legally gathered, strictly managed and respected. Only the data that is needed should be collected and processed.<\/p>\n<p>You can find out <a href=\"http:\/\/inchoo.net\/life-at-inchoo\/what-inchoo-did-to-prepare-for-gdpr\/\">what Inchoo did to prepare for GDPR<\/a> in our blog post by <a href=\"http:\/\/inchoo.net\/author\/toni\/profile\/\">Toni Anicic<\/a>.<\/p>\n<h2>Personal data in a Magento 2 project<\/h2>\n<p>Often when developing a Magento 2 project, data from a live Magento 2 website has to be used. Usually this means creating a copy of the website&#8217;s database structure and data, also known as a database dump. This database dump might include tables with personal user data such as names, addresses, emails, orders, invoices, etc. Having access to personal user data when it\u2019s not needed is considered bad practice as the data might get lost, stolen or become available to people that it\u2019s not intended for. Handling the user data this way can lead to significant GDPR penalties. Luckily, there is a way to avoid this by using a CLI tool called <strong>n98-<\/strong><b>magerun<\/b>.<\/p>\n<h2>Netz98 magerun CLI tools<b><\/b><\/h2>\n<p><a href=\"https:\/\/github.com\/netz98\/n98-magerun2\">N98-magerun2<\/a> provides some handy tools to work with Magento 2 from the command line. Among the available tools that n98-magerun provides is the database dump tool.<\/p>\n<h3>Installation<\/h3>\n<p>There are multiple ways to install n98-magerun2 in a Magento 2 project. We can download and install the phar file and make it executable or we can install the tool using Composer.<\/p>\n<h4>Install the phar file<\/h4>\n<p>To download the latest stable<strong> n98-magerun2.phar<\/strong> file, run this command in your Magento 2 project:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\"><span class=\"kw2\">wget<\/span> https:<span class=\"sy0\">\/\/<\/span>files.magerun.net<span class=\"sy0\">\/<\/span>n98-magerun2.phar<\/code><\/pre>\n<p>Or if you prefer to use Curl:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">curl <span class=\"re5\">-O<\/span> https:<span class=\"sy0\">\/\/<\/span>files.magerun.net<span class=\"sy0\">\/<\/span>n98-magerun2.phar<\/code><\/pre>\n<p>Verify the download by comparing the SHA256 checksum with the one on the website:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">shasum <span class=\"re5\">-a256<\/span> n98-magerun2.phar<\/code><\/pre>\n<p>We can make the phar file executable:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\"><span class=\"kw2\">chmod<\/span> +x .<span class=\"sy0\">\/<\/span>n98-magerun2.phar<\/code><\/pre>\n<p>It can now be called by using the PHP CLI interpreter:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">php n98-magerun2.phar <span class=\"br0\">&#123;<\/span><span class=\"kw3\">command<\/span><span class=\"br0\">&#125;<\/span><\/code><\/pre>\n<h4>Install with Composer<\/h4>\n<p>To install n98-magerun2 using Composer, inside a Magento 2 project run:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">composer require n98<span class=\"sy0\">\/<\/span>magerun2<\/code><\/pre>\n<p>If there is an error, try:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">composer require <span class=\"re5\">--no-update<\/span> n98<span class=\"sy0\">\/<\/span>magerun2\ncomposer update<\/code><\/pre>\n<p>N98-magerun2 commands are executed from the <strong>vendor\/bin\/<\/strong> folder. To verify the installation, run:<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">.<span class=\"sy0\">\/<\/span>vendor<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>n98-magerun2 <span class=\"re5\">--version<\/span><\/code><\/pre>\n<h2>Database dump<b><br \/>\n<\/b><\/h2>\n<p>The <strong>db:dump<\/strong> command is used to dump the project database. It uses mysqldump.<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">.<span class=\"sy0\">\/<\/span>vendor<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>n98-magerun2 db:dump<\/code><\/pre>\n<p>This command will create a file containing the database structure and all of the data.<\/p>\n<h3>Stripped database dump<\/h3>\n<p>The <b>db:dump<\/b> command has a <b>&#8211;strip<\/b> argument that can be used to exclude specific tables from the dump.<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">.<span class=\"sy0\">\/<\/span>vendor<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>n98-magerun2 db:dump <span class=\"br0\">[<\/span>--strip<span class=\"br0\">]<\/span><\/code><\/pre>\n<p>Tables that we want to exclude can be added to the <b>&#8211;strip<\/b> argument. Each of the tables should be separated by a <b>space<\/b>. Wildcards like <b>*<\/b> and <b>?<\/b> can be used in the table names to strip multiple tables.<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">.<span class=\"sy0\">\/<\/span>vendor<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>n98-magerun2 db:dump <span class=\"re5\">--strip<\/span>=\u201dcustomer_address<span class=\"sy0\">*<\/span> sales_invoice_<span class=\"sy0\">*<\/span>\u201d<\/code><\/pre>\n<h3>Table groups<\/h3>\n<p>Predefined table groups that start with <strong>@<\/strong> can also be used in the <b>&#8211;strip<\/b> argument. These contain a list of tables that will be excluded from the dump when the table group is used in the <b>&#8211;strip<\/b> argument.<\/p>\n<pre class=\"ish\"><code class=\"language-bash\">.<span class=\"sy0\">\/<\/span>vendor<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>n98-magerun2 db:dump <span class=\"re5\">--strip<\/span>=\u201d<span class=\"sy0\">@<\/span>stripped\u201d<\/code><\/pre>\n<p>The table groups are predefined in the <strong>config.yaml<\/strong> file either in the<strong> vendor\/n98\/magerun2\/<\/strong> folder or in the<strong> n98-magerun2.phar<\/strong> package.<\/p>\n<p>Available table groups:<\/p>\n<pre class=\"ish\"><code class=\"language-css\"><span class=\"co1\">@customers<\/span> customer_address<span class=\"sy0\">*<\/span> customer_entity<span class=\"sy0\">*<\/span> customer_grid_flat customer_log customer_visitor newsletter_subscriber product_alert<span class=\"sy0\">*<\/span> vault_payment_token<span class=\"sy0\">*<\/span> wishlist<span class=\"sy0\">*<\/span>\n&nbsp;\n<span class=\"co1\">@search<\/span> catalogsearch_<span class=\"sy0\">*<\/span>\n&nbsp;\n<span class=\"co1\">@sessions<\/span> core_session\n&nbsp;\n<span class=\"co1\">@log<\/span> log_url log_url_info log_visitor log_visitor_info log_visitor_online report_event report_compared_product_index report_viewed_<span class=\"sy0\">*<\/span>\n&nbsp;\n<span class=\"co1\">@quotes<\/span> quote quote_<span class=\"sy0\">*<\/span>\n&nbsp;\n<span class=\"co1\">@sales<\/span> sales_order sales_order_address sales_order_aggregated_created sales_order_aggregated_updated sales_order_grid sales_order_item sales_order_payment sales_order_status_history sales_order_tax sales_order_tax_item sales_invoice sales_invoice_<span class=\"sy0\">*<\/span> sales_invoiced_<span class=\"sy0\">*<\/span> sales_shipment sales_shipment_<span class=\"sy0\">*<\/span> sales_shipping_<span class=\"sy0\">*<\/span> sales_creditmemo sales_creditmemo_<span class=\"sy0\">*<\/span> sales_recurring_<span class=\"sy0\">*<\/span> sales_refunded_<span class=\"sy0\">*<\/span> sales_payment_<span class=\"sy0\">*<\/span> enterprise_sales_<span class=\"sy0\">*<\/span> enterprise_customer_sales_<span class=\"sy0\">*<\/span> sales_bestsellers_<span class=\"sy0\">*<\/span> paypal_billing_agreement<span class=\"sy0\">*<\/span> paypal_payment_transaction paypal_settlement_report<span class=\"sy0\">*<\/span>\n&nbsp;\n<span class=\"co1\">@admin<\/span> admin<span class=\"sy0\">*<\/span> authorization<span class=\"sy0\">*<\/span>\n&nbsp;\n<span class=\"co1\">@trade<\/span> <span class=\"co1\">@customers<\/span> <span class=\"co1\">@sales<\/span> <span class=\"co1\">@quotes<\/span>\n&nbsp;\n<span class=\"co1\">@stripped<\/span> <span class=\"co1\">@log<\/span> <span class=\"co1\">@sessions<\/span>\n&nbsp;\n<span class=\"co1\">@development<\/span> <span class=\"co1\">@admin<\/span> <span class=\"co1\">@trade<\/span> <span class=\"co1\">@stripped<\/span> <span class=\"co1\">@search<\/span><\/code><\/pre>\n<p>The <strong>@development<\/strong> table group includes other predefined table groups that contain sensitive user data such as logs, sessions, trade data, admin users, orders, invoices, credit memos, quotes, etc. This table group should be used when personal user data is not needed.<\/p>\n<p>The <strong>@development<\/strong> table group should take care of all customer data for a default Magento 2 project, but in many cases, a Magento 2 project will contain modules that create their own data tables. For customer data contained in tables not defined by the default Magento 2 project installation, custom table groups should be defined.<\/p>\n<h3>Custom table groups<\/h3>\n<p>In addition to the predefined table groups, custom table groups can also be defined. To define a custom table group, create a <strong>n98-magento2.yaml<\/strong> file inside the Magento 2 project <strong>app\/etc\/<\/strong> folder. The file should contain the following lines:<\/p>\n<pre class=\"ish\"><code class=\"language-yaml\"><span class=\"co1\"># app\/etc\/n98-magerun2.yaml<\/span>\n<span class=\"co1\"># ...<\/span><span class=\"co4\">\ncommands<\/span>:<span class=\"co4\"> N98\\Magento\\Command\\Database\\DumpCommand<\/span>:<span class=\"co4\"> table-groups<\/span>:<span class=\"co3\"> - id<\/span><span class=\"sy2\">: <\/span>table_group_name<span class=\"co3\"> description<\/span><span class=\"sy2\">: <\/span>table group description<span class=\"co3\"> tables<\/span><span class=\"sy2\">: <\/span>space separated list of tables\n<span class=\"co1\"># ...<\/span><\/code><\/pre>\n<p>This will create a new table group <b>@table_group_name<\/b> that can be used in the <b>&#8211;strip<\/b> argument to exclude the data specified inside this group.<\/p>\n<p>This way we can strip all of the personal user data that we do not need, making sure that the database dump is GDPR compliant and that the personal user data is never available if not needed.<\/p>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/inchoo.net\/magento-2\/gdpr-compliant-magento-2-database-dump\/\">GDPR compliant Magento 2 database dump<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/inchoo.net\">Inchoo<\/a>.<\/p>\n<h1><a target=\"_blank\" href=\"http:\/\/www.circulatetechnology.com\/\">Click here for more informations about top website development services <\/a><\/h1>\n","protected":false},"excerpt":{"rendered":"<p>On May 25th, a data privacy law known as GDPR came into effect. It impacts the way companies collect and handle user data. In this article we will show you how to handle personal user data when creating database dumps in order to avoid potential GDPR penalties. What is GDPR? In short, General Data Protection &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1121,1122,20,1123,19],"tags":[],"class_list":["post-132277","post","type-post","status-publish","format-standard","","category-database","category-gdpr","category-magento-2","category-magerun","category-php"],"jetpack_publicize_connections":[],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p99pkJ-ypv","_links":{"self":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/132277"}],"collection":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/comments?post=132277"}],"version-history":[{"count":0,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/132277\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/media?parent=132277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/categories?post=132277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/tags?post=132277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}