GithubHelp home page GithubHelp logo

greg0 / mysql-backup-golang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maurodelazeri/mysql-backup-golang

0.0 1.0 0.0 145 KB

Mysql backup golang

License: Apache License 2.0

Go 100.00%

mysql-backup-golang's Introduction

Mars

Overview

Mars is a tool for backing up multiple MySQL databases with multiples options. The backups are outputted as a .tar.gz and are stored locally, there is also support for retention in days/weeks/months

Usage

$ go run mars.go -help
  -hostname string
    	Hostname of the mysql server to connect to (default "localhost")
  -bind string
    	Port of the mysql server to connect to (default "3306")
  -password string
    	password of the mysql server to connect to (default "1234")
  -username string
    	username of the mysql server to connect to (default "root")
  -additionals string
    	Additional parameters that will be appended to mysqldump command
  -tablethreshold int
    	Do not split mysqldumps, if rowcount of table is less than dbthreshold value for table (default 5000000)      
  -batchsize int
    	Split mysqldumps in order to get each file contains batchsize number of records (default 1000000)
  -databases string
    	List of databases as comma seperated values to dump. OBS: If not specified, --all-databases is the default (default "--all-databases")
  -dbthreshold int
    	Do not split mysqldumps, if total rowcount of tables in database is less than dbthreshold value for whole database (default 10000000)
  -excluded-databases string
    	List of databases excluded to be excluded. OBS: Only valid if -databases is not specified
  -forcesplit
    	Split schema and data dumps even if total rowcount of tables in database is less than dbthreshold value. if false one dump file will be created
  -mysqldump-path string
    	Absolute path for mysqldump executable. (default "/usr/bin/mysqldump")
  -output-dir string
    	Default is the value of os.Getwd(). The backup files will be placed to output-dir {DATE/{DATABASE_NAME}/{DATABASE_NAME}_{TABLENAME|SCHEMA|DATA|ALL}_{TIMESTAMP}.sql
  -daily-rotation int
    	Number of days of retention (default 5)   	
  -weekly-rotation int
    	Number of weeks of retention (default 2)
  -monthly-rotation int
    	Number of months of retention (default 1) 
  -verbosity int
    	0 = only errors, 1 = important things, 2 = all (default 2)      
  -test
    	test

Rotation folders structure

mysqldump-path / daily|weekly|monthly / XXXX-XX-XX / {DATABASE_NAME}-XXXX-XX-XX / {DATABASE_NAME}{TABLENAME|SCHEMA|DATA|ALL}{TIMESTAMP}.tar.gz

Example

Running a backup of only one database:

$go run mars.go -username "root" -password "123456" -databases "mysql"

Running with parameters
{
	"HostName": "localhost",
	"Bind": "3306",
	"UserName": "root",
	"Password": "123456",
	"Databases": [
		"mysql"
	],
	"ExcludedDatabases": [],
	"DatabaseRowCountTreshold": 10000000,
	"TableRowCountTreshold": 5000000,
	"BatchSize": 1000000,
	"ForceSplit": false,
	"AdditionalMySQLDumpArgs": "",
	"Verbosity": 2,
	"MySQLDumpPath": "/usr/bin/mysqldump",
	"OutputDirectory": "/home/mauro/Downloads/mysql-dump-goland",
	"DefaultsProvidedByUser": true,
	"ExecutionStartDate": "2017-08-05T22:39:26.473773337-04:00",
	"DailyRotation": 5,
	"WeeklyRotation": 2,
	"MonthlyRotation": 1,
}
Running on operating system : linux
Processing Database : mysql
Getting tables for database : mysql
30 tables retrived : mysql
options.ForceSplit (false) && totalRowCount (2102) <= options.DatabaseRowCountTreshold (10000000)
Generating single file backup : mysql
mysqldump is being executed with parameters : -hlocalhost -uroot -p1234 -r/home/mauro/Downloads/mysql-dump-goland/daily/2017-08-05/mysql-2017-08-05/mysql_ALL_20170805.sql mysql
mysqldump output is : 
Compressing table file : /home/mauro/Downloads/mysql-dump-goland/daily/2017-08-05/mysql-2017-08-05/mysql_ALL_20170805.sql
Single file backup successfull : mysql
Processing done for database : mysql

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.