# 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
# Functions
BackupRotation execute a rotation of file, daily,weekly and monthly.
Compress compresses files into tar.gz file.
CopyDir recursively copies a directory tree, attempting to preserve permissions.
CopyFile copies the contents of the file named src to the file named by dst.
GetDatabaseList retrives list of databases on mysql.
GetOptions creates Options type from Commandline arguments.
GetTables retrives list of tables with rowcounts.
ListDirs give a Array of folders in a given path.
NewOptions returns a new Options instance.
NewTable returns a new Table instance.
WriteToFile create a file and writes a specified msg to it.