Exemplo n.º 1
0
//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
}
Exemplo n.º 2
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
}