This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************************************** | |
------------------------------------- | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************************************** | |
------------------------------------- | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************************************** | |
------------------------------------- | |
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************************************** | |
------------------------------------- | |
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use sqladmin; | |
DROP PROCEDURE | |
IF EXISTS archive; | |
delimiter // | |
CREATE PROCEDURE | |
archive() | |
begin | |
DECLARE rows INT; | |
DECLARE rows_deleted INT; |
NewerOlder