Search code examples
mysqlubuntubackup

Obfuscating personal data in MySQL backup


Tell me how to solve the problem with depersonalizing personal data of clients in the MySQL database. My task is to make personal data of clients depersonalized during backup - full name, email. There is an e-commerce CMS, and I want this data to be changed during backup. How to implement this? Are there any examples? I imagine this as data changes during backup on the fly. Another option is a copy of the database and data changes through sql queries, and then anonymous backup. Tell me how to do it right and if possible an example. Thanks.


Solution

  • I solved the problem with GDPR data by the usual data masking by MySQL functions.

    mysql -u %DB_LOGIN% -p%DB_PASSWORD% %GDPR_DB_NAME% -e "DROP DATABASE %GDPR_DB_NAME%"
    
    mysql -u %DB_LOGIN% -p%DB_PASSWORD% -e "CREATE DATABASE %GDPR_DB_NAME%"
    
    mysqldump -u %DB_LOGIN% -p%DB_PASSWORD% %DB_NAME% | mysql -u %DB_LOGIN% -p%DB_PASSWORD% %GDPR_DB_NAME%
    
    mysql -u %DB_LOGIN% -p%DB_PASSWORD% -D %GDPR_DB_NAME% -e "UPDATE "customer_address_entity" SET company = CONCAT(SUBSTR(company, 1, 6), REPEAT('*', CHAR_LENGTH(company) - 6));" -vvv