Skip to content

Instantly share code, notes, and snippets.

@neerajgupta2407
neerajgupta2407 / README.md
Created June 8, 2017 19:46 — forked from oodavid/README.md
Backup MySQL to Amazon S3

Backup MySQL to Amazon S3

This is a simple way to backup your MySQL tables to Amazon S3 for a nightly backup - this is all to be done on your server :-)

Sister Document - Restore MySQL from Amazon S3 - read that next

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc

import base64
import os
import time
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
"""
Desired Capabilities
"""
# TODO provide the desired cap as per your requirement
from datetime import timedelta
import jwt
import requests
from social_core.utils import handle_http_errors
from datetime import datetime, timezone
class AppleOAuth2():
"""apple authentication backend"""
@neerajgupta2407
neerajgupta2407 / Mock_requests_and_functions.py
Last active May 12, 2020 07:19
A custoom decorastor functions which can be used to mock the reqpose for particular function based on a flag called EnableMock. If EnableMock set to True, then mock_response will not execute the underlying function and returns the mock response provided in decorator.
"""
A custoom decorastor functions which can be used to mock the reqpose for particular
function based on a flag called EnableMock.
If EnableMock set to True, then mock_response will not execute the underlying function and returns the mock response provided in decorator.
"""
from functools import wraps
EnableMock = True
DummyRespone = 1000 # could be anything Int, Str, Float, Dict, list...
@neerajgupta2407
neerajgupta2407 / retry_request.py
Created May 12, 2020 07:25
Decorator used to retry the failed request with default retry limit to 3.
"""
Decorator used to retry the failed request with default retry limit to 3.
"""
import time
from functools import wraps
default_timeout = 1 # timeout of 1 sec.
def retry_request(retry_limit=3):
@neerajgupta2407
neerajgupta2407 / logger_function.py
Created May 12, 2020 07:31
A generic logger decorstor function which is used to log the function input and output at custom directory. @logs_func('dummy') will saves the results into /tmp/logs/dummy/date.txt
"""
A generic logger decorstor function which is used to log the function input and output at custom directory.
@logs_func('dummy') will saves the results into /tmp/logs/dummy/date.txt
"""
import os
from datetime import datetime
BASE_DIR="/tmp"
def get_dir(path):
@neerajgupta2407
neerajgupta2407 / Steps.
Last active May 16, 2020 13:04
Script used to add host machine ip address to Aws security group.
1. Configure Aws with command `aws configure --profile aws_user`
2. Run script to add Ip to security group. 'sh aws_add_ip_to_security_group.sh add'
# Installing ElasticSearch ANd Kibana
# Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update
sudo apt-get install elasticsearch kibana
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
Steps: 1)
sudo apt-get update
sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
2)
sudo vim /etc/apache2/sites-available/000-default.conf
@neerajgupta2407
neerajgupta2407 / export_and_upload_to_s3.sh
Last active January 15, 2021 19:03
Export POstgres db bbackup and upload to S3.
#!/bin/bash
# Written 2018-11-15 by 4410287
# This script will create a backup file of a postgres database and compress it. It is capable of access a local or remote server to pull the backup. After creating a new backup, it will delete backups that are older than 15 days, with the exception of backups created the first of every month. It is recommended to create a seperate database user specifically for backup purposes, and to set the permissions of this script to prevent access to the login details. Backup scripts for different databases should be run in seperate folders or they will overwrite each other.
HOSTNAME=
USERNAME=
PASSWORD=
DATABASE=
FILENAME=$(date +%Y-%m-%d).backup.sql