utils

package
v0.0.0-...-e3e8917 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BackupExample = "backup --dbname database --disable-compression\n" +
	"backup --dbname database --storage s3 --path /custom-path --disable-compression"
View Source
const MainExample = "mysql-bkup backup --dbname database --disable-compression\n" +
	"backup --dbname database --storage s3 --path /custom-path\n" +
	"restore --dbname database --file db_20231219_022941.sql.gz"
View Source
const RestoreExample = "restore --dbname database --file db_20231219_022941.sql.gz\n" +
	"restore --dbname database --storage s3 --path /custom-path --file db_20231219_022941.sql.gz"

Variables

View Source
var DatabaseName = ""
View Source
var Version = ""

Functions

func ChangePermission

func ChangePermission(filePath string, mod int)

func CheckEnvVars

func CheckEnvVars(vars []string) error

CheckEnvVars checks if all the specified environment variables are set

func ConvertBytes

func ConvertBytes(bytes uint64) string

ConvertBytes converts bytes to a human-readable string with the appropriate unit (bytes, MiB, or GiB).

func CopyFile

func CopyFile(src, dst string) error

func CronNextTime

func CronNextTime(cronExpr string) time.Time

CronNextTime returns cronExpression next time

func DeleteFile

func DeleteFile(filePath string) error

func EnvWithDefault

func EnvWithDefault(envName string, defaultValue string) string

func Error

func Error(msg string, args ...interface{})

Error logs error messages

func Fatal

func Fatal(msg string, args ...interface{})

func FileExists

func FileExists(filename string) bool

FileExists checks if the file does exist

func FlagGetBool

func FlagGetBool(cmd *cobra.Command, flagName string) bool

func FlagGetString

func FlagGetString(cmd *cobra.Command, flagName string) string

func GetEnv

func GetEnv(cmd *cobra.Command, flagName, envName string) string

func GetEnvVariable

func GetEnvVariable(envName, oldEnvName string) string

func GetIntEnv

func GetIntEnv(envName string) int

func Info

func Info(msg string, args ...interface{})

Info returns info log

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

func IsValidCronExpression

func IsValidCronExpression(cronExpr string) bool

IsValidCronExpression verify cronExpression and returns boolean

func MakeDir

func MakeDir(dirPath string) error

MakeDir create directory

func MakeDirAll

func MakeDirAll(dirPath string) error

MakeDirAll create directory

func NotifyError

func NotifyError(error string)

func NotifySuccess

func NotifySuccess(notificationData *NotificationData)

func SendEmail

func SendEmail(subject, body string) error

func SetEnv

func SetEnv(key, value string)

func TimeFormat

func TimeFormat() string

TimeFormat returns the format of the time

func Warn

func Warn(msg string, args ...interface{})

Warn returns warning log

func WriteToFile

func WriteToFile(filePath, content string) error

Types

type ErrorMessage

type ErrorMessage struct {
	Database        string
	EndTime         string
	Error           string
	BackupReference string
	DatabaseName    string
}

type MailConfig

type MailConfig struct {
	MailHost     string
	MailPort     int
	MailUserName string
	MailPassword string
	MailTo       string
	MailFrom     string
	SkipTls      bool
}

type NotificationData

type NotificationData struct {
	File            string
	BackupSize      string
	Database        string
	Duration        string
	Storage         string
	BackupLocation  string
	BackupReference string
}

Jump to

Keyboard shortcuts

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