Skip to content

Instantly share code, notes, and snippets.

awk -vDate=`date -d'now-2 hours' +[%Y-%m-%dT%H:%M:%S` '$4 > Date {print $1}' access.log | sort | uniq -c | sort -n | tail
@krasnuydyx
krasnuydyx / backup.sh
Created March 29, 2019 16:35
Simple backup script
#!/bin/bash
## Configuration
SRC_CODE="/var/jenkins_home"
BACKUP_DIR="/home/ec2-user/"
PROJECT_NAME="jenkins-vfqa"
DST_HOST="user@host"
REMOTE_DST_DIR="/root/backup"
EXCLUDES="-x '*/workspace/*' '*/jobs/*/builds/*' '*/jobs/*/lastStable/*' '*/jobs/*/lastSuccessful/*'"
BACKUP_DAILY=true # if set to false backup will not work
@krasnuydyx
krasnuydyx / sync.sh
Last active December 29, 2020 13:50
Environment sync (Magento Cloud)
#!/usr/bin/env bash
PROD_ENV="ent-tx3iahfl3v2uk-production-vohbr3y@ssh.us-3.magento.cloud"
STAGE_ENV="ent-tx3iahfl3v2uk-staging-5em2ouy@ssh.us-3.magento.cloud"
INT_ENV="tx3iahfl3v2uk-integration-5ojmyuq--mymagento@ssh.us-3.magento.cloud"
TIMEFORMAT=%R
db_data_reg="cat app/etc/env.php | grep -A 10 \"'db'\""
try() {
"$@" || { echo "command failed, with exit code $?"; exit 1; }
#You can pull this off using mysqldump. Here the catch: You cannot ship the data because there may be a cost associated with shipping the data.
#For this example, let's says you want to rename mydb to ourdb
#STEP 01 : Create the new database
mysql> CREATE DATABASE ourdb;
#STEP 02 : Get schema without the triggers
mysqldump -hrdshost -uuser -ppassword -d -t -R --skip-triggers mydb > /tmp/schema.sql
#STEP 03 : Get the triggers
@krasnuydyx
krasnuydyx / mysql_size.sh
Last active August 19, 2020 23:25
List sizes of MySQL databases
# Database size
SELECT
table_schema AS "Database name",
SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
# Database and index sizes
SELECT SUM(Data_length)/1024/1024/1024,SUM(Index_length)/1024/1024/1024 FROM information_schema.tables;
# WHERE table_schema = '';
@krasnuydyx
krasnuydyx / nginx.conf
Last active November 22, 2017 13:59
Nginx.conf optimized for magento
user nginx nginx;
worker_processes auto;
worker_rlimit_nofile 8192;
events {
worker_connections 8000;
}
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
http {
@krasnuydyx
krasnuydyx / proxy.pac
Created October 10, 2016 09:48
Auto proxy configuration for mac
function FindProxyForURL(url, host) {
PROXY = "PROXY 1.2.3.4"
// Apple.com via proxy
if (shExpMatch(host,"*.apple.com")) {
return PROXY;
}
// Everything else directly!
return "DIRECT";
}
@krasnuydyx
krasnuydyx / aws-s3-delete.sh
Last active November 22, 2017 14:00
AWS S3 console upload/download/delete
S3KEY=""
BUCKET=""
REGION="s3"
S3SECRET=""
file=$1
resource="/${BUCKET}/${file}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="DELETE\n\n${contentType}\n${dateValue}\n${resource}"