func (context *ElasticRuntime) directorCredentialsValid() (ok bool) { var directorInfo cfbackup.SystemDump if directorInfo, ok = context.SystemsInfo.SystemDumps[cfbackup.ERDirector]; ok { connectionURL := fmt.Sprintf(cfbackup.ERDirectorInfoURL, directorInfo.Get(cfbackup.SDIP)) gateway := context.HTTPGateway if gateway == nil { gateway = ghttp.NewHttpGateway() } _, err := gateway.Get(ghttp.HttpRequestEntity{ Url: connectionURL, Username: directorInfo.Get(cfbackup.SDUser), Password: directorInfo.Get(cfbackup.SDPass), ContentType: "application/json", })() ok = (err == nil) } return }
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 }