//Backup - method to execute backup
func (s *MysqlPlugin) Backup() (err error) {
	lo.G.Debug("Starting backup of mysql-tile")
	var writer io.WriteCloser
	var persistanceBackuper cfbackup.PersistanceBackup
	var mysqlUserName, mysqlPassword string
	var sshConfigs []command.SshConfig

	if sshConfigs, err = s.getSSHConfig(); err == nil {
		//take first node to execute backup on
		sshConfig := sshConfigs[0]
		if mysqlUserName, mysqlPassword, err = s.getMysqlCredentials(); err == nil {
			lo.G.Debug("Successfully got mysqlCredentials")
			if persistanceBackuper, err = s.GetPersistanceBackup(mysqlUserName, mysqlPassword, sshConfig); err == nil {
				if writer, err = s.PivotalCF.NewArchiveWriter(outputFileName); err == nil {
					defer writer.Close()
					lo.G.Debug("Starting mysql dump")
					err = persistanceBackuper.Dump(writer)
					lo.G.Debug("Dump finished", err)
				}
			}
		}
	}
	lo.G.Debug("Finished backup of mysql-tile", err)
	return
}
//Restore - method to execute restore
func (s *MysqlPlugin) Restore() (err error) {
	lo.G.Debug("Starting restore of mysql-tile")
	var reader io.ReadCloser
	var persistanceBackuper cfbackup.PersistanceBackup
	var mysqlUserName, mysqlPassword string

	var sshConfigs []command.SshConfig

	if sshConfigs, err = s.getSSHConfig(); err == nil {
		//take first node to execute restore on
		sshConfig := sshConfigs[0]

		if mysqlUserName, mysqlPassword, err = s.getMysqlCredentials(); err == nil {
			if persistanceBackuper, err = s.GetPersistanceBackup(mysqlUserName, mysqlPassword, sshConfig); err == nil {
				if reader, err = s.PivotalCF.NewArchiveReader(outputFileName); err == nil {
					defer reader.Close()
					if err = persistanceBackuper.Import(reader); err == nil {
						err = s.GetPrivilegeFlusher(sshConfig, mysqlPassword)
					}
				}
			}
		}
	}
	lo.G.Debug("Finished restore of mysql-tile", err)
	return
}
Example #3
0
func (context *ElasticRuntime) readWriterArchive(dbInfo cfbackup.SystemDump, databaseDir string, action int) (err error) {
	filename := fmt.Sprintf(ERBackupFileFormat, dbInfo.Get(cfbackup.SDComponent))
	filepath := path.Join(databaseDir, filename)

	var pb cfbackup.PersistanceBackup

	if pb, err = dbInfo.GetPersistanceBackup(); err == nil {
		switch action {
		case cfbackup.ImportArchive:
			lo.G.Debug("Restoring %s", dbInfo.Get(cfbackup.SDComponent))
			var backupReader io.ReadCloser
			if backupReader, err = context.Reader(filepath); err == nil {
				defer backupReader.Close()
				err = pb.Import(backupReader)
				lo.G.Debug("Done restoring %s", dbInfo.Get(cfbackup.SDComponent))
			}
		case cfbackup.ExportArchive:
			lo.G.Info("Exporting %s", dbInfo.Get(cfbackup.SDComponent))
			var backupWriter io.WriteCloser
			if backupWriter, err = context.Writer(filepath); err == nil {
				defer backupWriter.Close()
				err = pb.Dump(backupWriter)
				lo.G.Debug("Done backing up %s", dbInfo.Get(cfbackup.SDComponent))
			}
		}
	}
	return
}