use regular expression and this "\033\[[0-9;]*[mGK]"
Friday, April 19, 2024
Saturday, March 9, 2024
mysql replication
generally follow this procedure, it's working fine: https://learn.microsoft.com/en-us/azure/mysql/single-server/how-to-data-in-replication
install mydumper on a MySQL source server:
apt-get install mydumper
Turn on binary logging. In the mysqld section, add following line:
log-bin=mysql-bin.log
Restart the server
Set your DB to read only mode:
mysql -uUserName -pPassWord -DDatabaseName <<<"FLUSH TABLES WITH READ LOCK;"
mysql -uUserName -pPassWord -DDatabaseName <<<"SET GLOBAL read_only = 1;"
Check your master status, run this at the beginnig of the running the backup:
mysql -uUserName -pPassWord -DDatabaseName <<<"show master status;"
mysql: [Warning] Using a password on the command line interface can be insecure.
File Position Binlog_Do_DB Binlog_Ignore_DB Executed_Gtid_Set
mysql-bin.000084 522687808
Dump required databases:
mydumper --regex='^(?!(backup|percona|mysql|sys|information_schema|performance_schema))' --host=localhost --user=UserName --password=PassWord --outputdir=backup --rows=500000 --compress --build-empty-files --threads=16 --compress-protocol --kill-long-queries --lock-all-tables -L mydumper-logs.txt
Check again after running the backup:
mysql -uUserName -pPassWord -DDatabaseName <<<"show master status;"
This should have a same value as previous.
When backup is finished unlock tables:
mysql -uUserName -pPassWord -DDatabaseName <<<"SET GLOBAL read_only = OFF;"
mysql -uUserName -pPassWord -DDatabaseName <<<"UNLOCK TABLES;"
Restore databases:
myloader -h 'mysql.mysql.database.azure.com' --user=UserName --password=PassWord --directory=/var/lib/mysql/backup --queries-per-transaction=500 --threads=16 --compress-protocol --verbose=3 -e 2>myloader-logs.txt
Create a user on source server:
CREATE USER 'syncuser'@'%' IDENTIFIED BY 'yourpassword';
GRANT REPLICATION SLAVE ON *.* TO ' syncuser'@'%';
Setup synchronization on destination machine:
CALL mysql.az_replication_change_master('yourVmName.uksouth.cloudapp.azure.com', 'syncuser', 'yourpassword', 3306, 'mysql-bin.000084', 522687808, '');
Check status:
show slave status;
Start synchronization:
CALL mysql.az_replication_start;
Troubleshooting:
Example error: Worker 1 failed executing transaction 'ANONYMOUS' at master log mysql-bin.000084, end_log_pos 526850979; Error executing row event: 'Table 'Table1' doesn't exist'
Solution: filter this Table1 on Azure portal:
Check for errors:
select * from performance_schema.replication_applier_status_by_worker;
Tuesday, January 9, 2024
copy SSRS report
1. Download https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/features/reporting-services/ssrs-migration-rss/ssrs_migration.rss
2. execute C:\rss>"C:\Program Files\Microsoft SQL Server Reporting Services\Shared Tools\RS.exe" -i ssrs_migration.rss -e Mgmt2010 -s https://source/reportserver -v ts="http://destination/Reportserver"
Sunday, January 7, 2024
tips for securing environment
1. Pass the hash mitigation:
Security descriptor is a lock (as opposed to access tokens), those define who has access to which resource, it cotains DACL (actual permision list) and SACL (auditing info) and ownership info.
DACL is managed by someone who have a "Full Controll" permissions, SACL can be managed only by someone who has a user privilige (usually means belonging to local admin group)
Rule sets are read from top down and inherted have lower priority than local:
Deny always wins if this set by a group as opposed to inherited permissions.
Priviliges always beat permissions.
Even if a domain admin set a DENY permission on "take ownership" permission for a local admin, because of this privilige "Take ownership of files and other objects"
Tip for connecting to a user session that is disconnected: start taskmgr as SYSTEM and connect, you will not be asked for a password.
Wednesday, December 27, 2023
app locker
Use GPO and inheritance of GPO. Create two AD groups:
BTW2. This blocks 95% of malware from running
Thursday, December 21, 2023
UnInstallation of obsolete .net
Start-BitsTransfer "https://github.com/dotnet/cli-lab/releases/download/1.6.0/dotnet-core-uninstall-1.6.0.msi" -Destination c:\temp\dotnet-core-uninstall-1.6.0.msi
.\dotnet-core-uninstall-1.6.0.msi
cd 'C:\Program Files (x86)\dotnet-core-uninstall\'
.\dotnet-core-uninstall list
28 .\dotnet-core-uninstall dry-run
30 .\dotnet-core-uninstall dry-run --hosting-bundle 3.1.26
31 .\dotnet-core-uninstall remove --hosting-bundle 3.1.26
32 .\dotnet-core-uninstall list
33 .\dotnet-core-uninstall dry-run --runtime 3.1.26
34 .\dotnet-core-uninstall remove --runtime 3.1.26
Get-WmiObject -Class Win32_Product | Format-Table
Tuesday, December 5, 2023
Analysis of storage analytics logs
https://learn.microsoft.com/en-us/azure/storage/common/storage-analytics
1. Setup Azure Log analytics, see above
2. Download blobs from $log container, use storage explorer.
3. Build a single csv using this file.
.\XLog2CSV.ps1 -inputFolder "C:\temp\orthanc\blob\2023\11\" -outputFile c:\temp\november.csv
4. Import CSV into sql.
5.Analysis