Skip to content

Instantly share code, notes, and snippets.

@ihanick
ihanick / create_rocky9vm.sh
Created July 30, 2024 19:41
Create and setup virtual machine using virt-install, Rocky Linux 9 and kickstart
#!/bin/bash
wget https://github.com/rocky-linux/kickstarts/raw/r9/Rocky-9-Vagrant-Libvirt.ks
patch <<EOF
--- Rocky-9-Vagrant-Libvirt.ks.orig 2024-07-30 22:35:00.629119036 +0300
+++ Rocky-9-Vagrant-Libvirt.ks 2024-07-30 22:35:52.690757566 +0300
@@ -22,7 +22,7 @@
skipx
# System services
-services --enabled="vmtoolsd"
@ihanick
ihanick / longhorn-talos-frecracker.md
Created July 25, 2024 11:43
Talos is a good target for microvm and it works without modification on the Firecracker microvm
@ihanick
ihanick / pgdump-k8s-cronjob.yaml
Created May 8, 2023 12:35
Create a cron job to make a logical backup with pgdump in the kubernetes, upload the backup to S3 storage
apiVersion: batch/v1
kind: CronJob
metadata:
name: cluster1-pgdump-backup
spec:
schedule: "11 * * * *"
jobTemplate:
spec:
template:
spec:
@ihanick
ihanick / build.sh
Created April 27, 2023 10:25
Create a pod using kubernetes rest
kubectl run kaniko --rm -i --restart=Never \
--image=gcr.io/kaniko-project/executor:latest \
--env="DOCKER_USERNAME=$DOCKER_USERNAME" \
--env="DOCKER_PASSWORD=$DOCKER_PASSWORD" \
--env="DOCKER_REGISTRY=docker.io" \
--command -- /bin/bash <<EOF
/kaniko/executor \
--context=dir:///build \
--dockerfile=/dev/stdin \
--destination=docker.io/$DOCKER_USERNAME/k8spodcreator:1.0 \
@ihanick
ihanick / proxysql-sync-crontab
Created February 10, 2021 06:46
sync proxysql users with cron job
## Create a table and fill it with first checksum:
# create table percona.users_crc(id int primary key, crc varchar(10));
# replace into percona.users_crc SELECT 1,CONV(BIT_XOR(CAST(CRC32(concat(user,host,`plugin`,authentication_string)) AS UNSIGNED)), 10, 16) from mysql.user;
*/5 * * * * root test $(mysql --host pxc-name-or-ip --user root -psecret -Ne 'select crc into @old_crc from percona.users_crc LIMIT 1;replace into percona.users_crc SELECT 1,CONV(BIT_XOR(CAST(CRC32(concat(user,host,`plugin`,authentication_string)) AS UNSIGNED)), 10, 16) from mysql.user; select count(*) from percona.users_crc where crc <> @old_crc') -gt 0 && /usr/bin/proxysql-admin --syncusers
@ihanick
ihanick / gen_import_commands.sql
Created June 8, 2019 09:33
Generates copy and import commands for partial backups created by xtrabackup: mysql -N test < gen_import_commands.sql|perl -pe 's/\\!/\!/g;s/\\n/\n/g;s,\\\\,\\,g'
set @bkpdir := '/home/root/backup';
set @dtdir := '/var/lib/mysql';
set @usr := 'mysql:mysql';
-- !@#$%^&*()-=+_.,;:"'\/
DROP FUNCTION IF EXISTS TBL_TO_MYSQL_FILENAME;
CREATE FUNCTION TBL_TO_MYSQL_FILENAME(s TEXT) RETURNS TEXT DETERMINISTIC
RETURN
REPLACE(
REPLACE(
https://github.com/percona/percona-server.git 70148a7d330919102bf4579380aedca4df9fdbfa
Test case:
1. setup
create database test;
use test
create table t (c int auto_increment primary key, c1 varchar(255));
insert into t (c) values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
insert into t (c) values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
insert into t (c) select NULL from t t1, t t2, t t3, t t4, t t5;
@ihanick
ihanick / mysqlcli2mext.pl
Created December 28, 2017 03:47
convert SHOW STATUS output to mysqladmin ext output used by pt-mext
#!/usr/bin/env perl
# Usage
# 1. Save show status output in a file, e.g. run inside mysql cli:
# mysql> tee report.txt
# mysql> SHOW STATUS;select sleep(1);SHOW STATUS;select sleep(1);SHOW STATUS;select sleep(1);SHOW STATUS;select sleep(1);SHOW STATUS;select sleep(1);
# mysql> notee
# 2. perl mysqlcli2mext.pl < report.txt
# 3. pt-mext -r -- cat report.txt
$print_next=0;
$prev_line='';
@ihanick
ihanick / move_file_to_workdir.py
Last active April 10, 2020 14:43
Convert vertical show processlist output to one query per line for better filtering with awk or cut
# get only queries from processlist and apply count(*) group by query
prlist_lines.sh 2017_08_31_00_14_51-processlist |sed -e 's/^.*Info://' | sort |uniq -c |sort -n
@ihanick
ihanick / build-mysql-start.sh
Created December 17, 2016 09:03
how to run mysql from source code
#!/bin/bash -e
# git clone https://github.com/mysql/mysql-server
# cd mysql-server; git checkout 8.0
# ../build-mysql.sh 8.0 rel
REPO=$PWD
VER=$1
DESC=`git log -1 --pretty=%B|xargs`
if [ "x${VER}" = "x" ] ; then
VER=56