Coder Social home page Coder Social logo

jenkinsmysqlbackuptoawss3's Introduction

JenkinsMySqlBackupToAwsS3

Create backup of MySql db and store it in S3 with use of Jenkins job

Prerequisites:

  • ssh keys generated and stored in centos folder and private key copied to container jenkins-aws:/tmp/remote-key
  • aws user_id and secret_key adjusted
  1. Run containers:
docker-compose build
docker-compose up
  1. Create database in db containers and example table
docker exec -it db bash
mysql -u root -h db_host -p
create database testdb;
use testdb;
create table info(name varchar(20), age int(2));
show tables;
desc info;  
insert into info values ('rafa', '30');
select * from info;
  1. make a script executable which will allso alow jenkins to execute the script on the remote-host-aws container
chmod -x centos/script-mysql-backup.sh
  1. in jenkins, add required in the script parameters, secrets, create a job and run it
  • add this executable script to jenkins job:
bash /tmp/script-mysql-backup.sh $DB_HOST_PARAM $DB_PASSWD_PARAM $DB_NAME_PARAM $AWS_USER_ID_PARAM $AWS_USER_SECRET_PARAM $AWS_BUCKET_NAME_PARAM
  1. run job externaly:
  • generate crumb token in shell:
crumb=$(curl -u "user:password" -s 'http://localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
  • use that crumb token to run job with no parameters
curl -u "user:password" \
    -H "$crumb" \
    -X POST "http://localhost:8080/job/<<job-name>>/build?delay=0sec"
  • use that crumb token to run job with no parameters
curl -u "user:password" \
    -H "$crumb" \
    -X POST "http://localhost:8080/job/<<job-name>>/buildWithParameters?DB_HOST_PARAM=db_host&DB_NAME_PARAM=testdb&AWS_BUCKET_NAME_PARAM=jenkins-mysql-backup-example-123&AWS_USER_ID_PARAM=AKIAQL54MMB3PAO532WU"

jenkinsmysqlbackuptoawss3's People

Contributors

klimuntowskirafal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.