Skip to content

Instantly share code, notes, and snippets.

View SQLadmin's full-sized avatar

SqlAdmin SQLadmin

View GitHub Profile
@SQLadmin
SQLadmin / xtrabackup_full_increment_restore.sh
Last active March 15, 2024 17:34
Automate xtrabackup for FULL/Incremental and restore
#!/bin/bash
# This is my production backup script.
# https://sqlgossip.com
set -e
set -u
usage() {
echo "usage: $(basename $0) [option]"
echo "option=full: Perform Full Backup"
/*****************************************************************
-------------------------------------
tsqltools - RDS - Auto CDC
-------------------------------------
Description: This stored procedure will help you to enable CDC
automatically when a tables is created. This is basically a database
Trigger and it'll ecxecute enable CDC procedure when we creat a
new table. This is a database level trigger, so it won't replicate
the new tables which are in another database.
/*****************************************************************
-------------------------------------
tsqltools - RDS - Auto CDC
-------------------------------------
Description: This stored procedure will help you to enable CDC
automatically when a tables is created. This is basically a database
Trigger and it'll ecxecute enable CDC procedure when we creat a
new table. This is a database level trigger, so it won't replicate
the new tables which are in another database.
/*****************************************************************
-------------------------------------
tsqltools - RDS - Auto CDC
-------------------------------------
Description: This stored procedure will help you to enable CDC
automatically when a tables is created. This is basically a database
Trigger and it'll ecxecute enable CDC procedure when we creat a
new table. This is a database level trigger, so it won't replicate
the new tables which are in another database.
How to Run: If you to enable this on DBAdmin database,
/*****************************************************************
-------------------------------------
tsqltools - RDS Add CDC
-------------------------------------
Description: This stored procedure will help you to enable CDC on
all the exsiting tables. You have to run this store procedure on the
database where you need to add the tables. It won't support Cross
database's tables.
How to Run: If you want to enable CDC on the tables which
all are in DBAdmin database,
#Retrieve the AWS instance ID, keep trying until the metadata is available
$instanceID = "null"
while ($instanceID -NotLike "i-*") {
Start-Sleep -s 3
$instanceID = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/instance-id
}
#Pass Domain Creds
$username = "sqladmin\Administrator"
$password = "mypassword" | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential($username, $password)
#!/bin/bash
# ----------------------------------------------------------
# RECREATE REDSHIFT CLUSTERS FROM RUNNING CLUSTER'S SNAPSHOT
# ----------------------------------------------------------
# Version: 1.0
# Created by: @SQLadmin
# Create IAM user with keys assign Redshift nessessary access
# and SES send raw email access
#!/bin/bash
# pass variables
archive_dbname=$1
archive_table=$2
archive_column=$3
days_to_archive=$4
archive_date="'"`date +'%Y-%m-%d' --date="-$days_to_archive day"`"'"
where_clause=$archive_column'<='$archive_date
dump_file=$archive_table_`date +'%Y-%m-%d' --date="-$days_to_archive day"`".sql"
use sqladmin;
DROP PROCEDURE
IF EXISTS sqladmin_archive;
delimiter //
CREATE PROCEDURE
sqladmin_archive(IN archive_dbname varchar(100), IN archive_table varchar(100), IN archive_column varchar(100), IN archive_date varchar(100))
begin
DECLARE rows INT;
use sqladmin;
DROP PROCEDURE
IF EXISTS archive;
delimiter //
CREATE PROCEDURE
archive()
begin
DECLARE rows INT;
DECLARE rows_deleted INT;