Example #1
0
func (mysqlTask *backupMySQLTask) GenerateTmpFile(tmpFilePath string) ([]byte, error) {
	database := mysqlTask.config.Params["db_base"]
	tables := mysqlTask.config.Params["db_tables"]
	password := mysqlTask.config.Params["db_pass"]

	if len(database) == 0 && len(tables) == 0 {
		database = "--all-databases"
	}

	if len(password) != 0 {
		password = fmt.Sprintf("MYSQL_PWD=%s", password)
	}

	params := &mysqlTask.config.Params

	cmd := fmt.Sprintf("%s mysqldump -h %s -P %s -u %s %s %s %s > %s",
		password,
		(*params)["db_host"],
		(*params)["db_port"],
		(*params)["db_user"],
		database,
		tables,
		mysqlTask.compressionFilter(),
		tmpFilePath,
	)

	out, err := hmutil.System(cmd)
	if len(out) > 0 {
		err = errors.New("mysqldump failed")
	}

	return out, err
}
func (postgresTask *backupPostgresTask) GenerateTmpFile(tmpFilePath string) ([]byte, error) {

	tables := postgresTask.config.Params["db_tables"]

	if len(tables) == 0 {
		tables = "\\*"
	}

	params := &postgresTask.config.Params

	cmd := fmt.Sprintf("PGPASSWORD=%s pg_dump %s -h %s -p %s -U %s %s %s %s >%s",
		(*params)["db_pass"],
		postgresTask.recreateFlag(),
		(*params)["db_host"],
		(*params)["db_port"],
		(*params)["db_user"],
		(*params)["db_base"],
		postgresTask.tablesFlag(),
		postgresTask.compressionFilter(),
		tmpFilePath,
	)

	out, err := hmutil.System(cmd)
	if len(out) > 0 {
		err = errors.New("pg_dump failed")
	}

	return out, err
}
Example #3
0
func (m *Manager) writeCrontab(schedule string, cmd string) error {
	taskFormat := `crontab -l\
    | ( grep -v 'gobackuper %s' ; echo '%s %s %s gobackuper %s >> /var/log/gobackuper_cron.log 2>&1' )\
    | crontab`
	task := fmt.Sprintf(taskFormat, cmd, schedule, CRON_PATH, CRON_GOTRACEBACK, cmd)
	_, err := hmutil.System(task)
	return err
}
func (m *Manager) writeCrontab(schedule string, cmd string) error {
	// taskFormat := "schtasks /Create /TR \"%s %s\" /TN %s /SC MINUTE /MO %v"
	taskFormat := `schtasks /Create /TR "%s %s" /TN %s /SC MINUTE /MO %v`
	time := toMinutes(strings.Split(schedule, " ")[0:2])
	path := "D:\\src\\github.com\\Twizty\\cbackup\\backuper\\backuper.exe"
	taskFormat = fmt.Sprintf(taskFormat, path, cmd, "gobackuper_"+cmd, time)
	batFile := "C:\\tmp\\sche.bat"

	f, _ := os.Create(batFile)
	f.Write([]byte(taskFormat))
	f.Close()
	_, err := hmutil.System(batFile)
	// fmt.Println(string(res))
	os.Remove(batFile)
	return err
}