mysql-backup-golang

command module
v0.0.0-...-4a36df9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

README

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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL