clientv3/snapshot/v3_snapshot.go
func (s *v3Manager) Restore(cfg RestoreConfig) error {
	pURLs, err := types.NewURLs(cfg.PeerURLs)
	if err != nil {
		return err
	}
	var ics types.URLsMap
	ics, err = types.NewURLsMap(cfg.InitialCluster)
	if err != nil {
		return err
	}

	srv := etcdserver.ServerConfig{
		Logger:              s.lg,
		Name:                cfg.Name,
		PeerURLs:            pURLs,
		InitialPeerURLsMap:  ics,
		InitialClusterToken: cfg.InitialClusterToken,
	}
	if err = srv.VerifyBootstrap(); err != nil {
		return err
	}

	s.cl, err = membership.NewClusterFromURLsMap(s.lg, cfg.InitialClusterToken, ics)
	if err != nil {
		return err
	}

	dataDir := cfg.OutputDataDir
	if dataDir == "" {
		dataDir = cfg.Name + ".etcd"
	}
	if fileutil.Exist(dataDir) {
		return fmt.Errorf("data-dir %q exists", dataDir)
	}

	walDir := cfg.OutputWALDir
	if walDir == "" {
		walDir = filepath.Join(dataDir, "member", "wal")
	} else if fileutil.Exist(walDir) {
		return fmt.Errorf("wal-dir %q exists", walDir)
	}

	s.name = cfg.Name
	s.dbPath = cfg.SnapshotPath
	s.walDir = walDir
	s.snapDir = filepath.Join(dataDir, "member", "snap")
	s.skipHashCheck = cfg.SkipHashCheck

	s.lg.Info(
		"restoring snapshot",
		zap.String("path", s.dbPath),
		zap.String("wal-dir", s.walDir),
		zap.String("data-dir", dataDir),
		zap.String("snap-dir", s.snapDir),
	)
	if err = s.saveDB(); err != nil {
		return err
	}
	if err = s.saveWALAndSnap(); err != nil {
		return err
	}
	s.lg.Info(
		"restored snapshot",
		zap.String("path", s.dbPath),
		zap.String("wal-dir", s.walDir),
		zap.String("data-dir", dataDir),
		zap.String("snap-dir", s.snapDir),
	)

	return nil
}
func (s *v3Manager) Restore(cfg RestoreConfig) error {
	pURLs, err := types.NewURLs(cfg.PeerURLs)
	if err != nil {
		return err
	}
	var ics types.URLsMap
	ics, err = types.NewURLsMap(cfg.InitialCluster)
	if err != nil {
		return err
	}

	srv := etcdserver.ServerConfig{
		Logger:              s.lg,
		Name:                cfg.Name,
		PeerURLs:            pURLs,
		InitialPeerURLsMap:  ics,
		InitialClusterToken: cfg.InitialClusterToken,
	}
	if err = srv.VerifyBootstrap(); err != nil {
		return err
	}

	s.cl, err = membership.NewClusterFromURLsMap(s.lg, cfg.InitialClusterToken, ics)
	if err != nil {
		return err
	}

	dataDir := cfg.OutputDataDir
	if dataDir == "" {
		dataDir = cfg.Name + ".etcd"
	}
	if fileutil.Exist(dataDir) {
		return fmt.Errorf("data-dir %q exists", dataDir)
	}

	walDir := cfg.OutputWALDir
	if walDir == "" {
		walDir = filepath.Join(dataDir, "member", "wal")
	} else if fileutil.Exist(walDir) {
		return fmt.Errorf("wal-dir %q exists", walDir)
	}

	s.name = cfg.Name
	s.dbPath = cfg.SnapshotPath
	s.walDir = walDir
	s.snapDir = filepath.Join(dataDir, "member", "snap")
	s.skipHashCheck = cfg.SkipHashCheck

	s.lg.Info(
		"restoring snapshot",
		zap.String("path", s.dbPath),
		zap.String("wal-dir", s.walDir),
		zap.String("data-dir", dataDir),
		zap.String("snap-dir", s.snapDir),
	)
	if err = s.saveDB(); err != nil {
		return err
	}
	if err = s.saveWALAndSnap(); err != nil {
		return err
	}
	s.lg.Info(
		"restored snapshot",
		zap.String("path", s.dbPath),
		zap.String("wal-dir", s.walDir),
		zap.String("data-dir", dataDir),
		zap.String("snap-dir", s.snapDir),
	)

	return nil
}
func ( s * v3Manager ) Restore ( cfg RestoreConfig ) error { pURLs , err := types . NewURLs ( cfg . PeerURLs ) if err != nil { return err } var ics types . URLsMap ics , err = types . NewURLsMap ( cfg . InitialCluster ) if err != nil { return err } srv := etcdserver . ServerConfig { Logger : s . lg , Name : cfg . Name , PeerURLs : pURLs , InitialPeerURLsMap : ics , InitialClusterToken : cfg . InitialClusterToken , } if err = srv . VerifyBootstrap ( ) ; err != nil { return err } s . cl , err = membership . NewClusterFromURLsMap ( s . lg , cfg . InitialClusterToken , ics ) if err != nil { return err } dataDir := cfg . OutputDataDir if dataDir == " " { dataDir = cfg . Name + " " } if fileutil . Exist ( dataDir ) { return fmt . Errorf ( " " , dataDir ) } walDir := cfg . OutputWALDir if walDir == " " { walDir = filepath . Join ( dataDir , " " , " " ) } else if fileutil . Exist ( walDir ) { return fmt . Errorf ( " " , walDir ) } s . name = cfg . Name s . dbPath = cfg . SnapshotPath s . walDir = walDir s . snapDir = filepath . Join ( dataDir , " " , " " ) s . skipHashCheck = cfg . SkipHashCheck s . lg . Info ( " " , zap . String ( " " , s . dbPath ) , zap . String ( " " , s . walDir ) , zap . String ( " " , dataDir ) , zap . String ( " " , s . snapDir ) , ) if err = s . saveDB ( ) ; err != nil { return err } if err = s . saveWALAndSnap ( ) ; err != nil { return err } s . lg . Info ( " " , zap . String ( " " , s . dbPath ) , zap . String ( " " , s . walDir ) , zap . String ( " " , dataDir ) , zap . String ( " " , s . snapDir ) , ) return nil }
// Restore restores a new etcd data directory from given snapshot file.
Restore restores a new etcd data directory from given snapshot file .