Migrating Ezeelogin database manually when the table size is large for faster Ezeelogin software upgrades
How to manually migrate Ezeelogin databases for faster Ezeelogin upgrade?
Overview: This article helps Ezeelogin admin users to manually migrate Ezeelogin databases when the row count of the database tables gwactivity_logs, serveractivity_logs, webactivity_logs, sshlogs exceeds 500,000 entries for faster Ezeelogin upgrade.
Manual migration of the Ezeelogin database becomes necessary when the row count in tables such as serveractivity_logs, webactivity_logs, and sshlogs exceeds 500,000 entries. This large row count typically results from a large number of Ezeelogin gateway users accessing remote servers.
Step 1: Run the following command to find out the count for log tables in the database of the Ezeelogin gateway server before performing the upgrade. Enter the MySQL root password when it prompted
mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf); SELECT 'gwactivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)gwactivity_logs UNION ALL SELECT 'serveractivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)serveractivity_logs UNION ALL SELECT 'webactivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)webactivity_logs UNION ALL SELECT 'sshlogs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)sshlogs UNION ALL SELECT 'authlogs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)authlogs;"
mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf); SELECT 'gwactivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)gwactivity_logs UNION ALL SELECT 'serveractivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)serveractivity_logs UNION ALL SELECT 'webactivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)webactivity_logs UNION ALL SELECT 'sshlogs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)sshlogs;"
Enter password:
+---------------------+----------+
| gwactivity_logs | COUNT(*) |
+---------------------+----------+
| gwactivity_logs | 38554 |
| serveractivity_logs | 1545 |
| webactivity_logs | 12842 |
| sshlogs | 8145 |
+---------------------+----------+
If the counts of the tables are greater than 500,000 tuples, first take a database dump, table dump, and then truncate the table in the database before performing the upgrade.
mkdir ezlogin_backup_$(date +%Y-%m-%d)/ezlogin -p
db_name=$(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf) && file="${db_name}_old_$(date +%Y-%m-%d).sql" && mysqldump -u root -p "$db_name" > "$file" && cp "$file" "ezlogin_backup_$(date +%Y-%m-%d)/"
cp /usr/local/etc/ezlogin/* ezlogin_backup_$(date +%Y-%m-%d)/ezlogin
mysqldump -u root -p $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf) $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)gwactivity_logs > $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)gwactivity_logs_$(date +%Y-%m-%d).sql
mysqldump -u root -p $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf) $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)serveractivity_logs > $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)serveractivity_logs_$(date +%Y-%m-%d).sql
mysqldump -u root -p $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf) $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)webactivity_logs > $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)webactivity_logs_$(date +%Y-%m-%d).sql
mysqldump -u root -p $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf) $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)sshlogs > $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)sshlogs_$(date +%Y-%m-%d).sql
grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf > old_dbprefix_$(date +%Y-%m-%d).txt
mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf); truncate table $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)gwactivity_logs;"
mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf); truncate table $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)serveractivity_logs;"
mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf); truncate table $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)webactivity_logs;"
mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf); truncate table $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)sshlogs;"
Follow the below steps after upgrading Ezeelogin
Step 7: Replace the old_db_prefix with the new_db_prefix(db_prefix will be changed after the upgrade). You can view the new db_prefix from /usr/local/etc/ezlogin/ez.conf after upgrade.
grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf
cp *_gwactivity_logs_$(date +%Y-%m-%d).sql ezlogin_backup_$(date +%Y-%m-%d)
cp *_serveractivity_logs_$(date +%Y-%m-%d).sql ezlogin_backup_$(date +%Y-%m-%d)
cp *_webactivity_logs_$(date +%Y-%m-%d).sql ezlogin_backup_$(date +%Y-%m-%d)
cp *_sshlogs_$(date +%Y-%m-%d).sql ezlogin_backup_$(date +%Y-%m-%d)
sed -i 's/old_dbprefix/new_dbprefix/g' copy.sql
For example:
old_dbprefix : cat old_dbprefix_$(date +%Y-%m-%d).txt
new_dbprefix : grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf
sed -i 's/old_/new_/g' xxxxx_gwactivity_logs_xxxx-xx-xx.sql
sed -i 's/old_/new_/g' xxxxx_serveractivity_logs_xxxx-xx-xx.sql
sed -i 's/old_/new_/g' xxxxx_webactivity_logs_xxxx-xx-xx.sql
sed -i 's/old_/new_/g' xxxxx_sshlogs_xxxx-xx-xx.sql
db_name=$(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf) && file="${db_name}_new_$(date +%Y-%m-%d).sql" && mysqldump -u root -p "$db_name" > "$file" && cp "$file" "ezlogin_backup_$(date +%Y-%m-%d)/"
mysql -u ezlogin_pyy -p P4&][*V]Qx3jn3n7A6@p6p7]G ezlogin_serd < xxxxx_gwactivity_logs_xxxx-xx-xx.sql
mysql -u ezlogin_pyy -p P4&][*V]Qx3jn3n7A6@p6p7]G ezlogin_serd < xxxxx_serveractivity_logs_xxxx-xx-xx.sql
mysql -u ezlogin_pyy -p P4&][*V]Qx3jn3n7A6@p6p7]G ezlogin_serd < xxxxx_webactivity_logs_xxxx-xx-xx.sql
mysql -u ezlogin_pyy -p P4&][*V]Qx3jn3n7A6@p6p7]G ezlogin_serd < xxxxx_sshlogs_xxxx-xx-xx.sql
mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf); SELECT 'gwactivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)gwactivity_logs UNION ALL SELECT 'serveractivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)serveractivity_logs UNION ALL SELECT 'webactivity_logs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)webactivity_logs UNION ALL SELECT 'sshlogs', COUNT(*) FROM $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)sshlogs;"
Related Articles: