code: func (db *DB) Snapshot(dir string, withHead bool) error {
  	if dir == db.dir {
  		return errors.Errorf("cannot snapshot into base directory")
  	}
  	if _, err := ulid.ParseStrict(dir); err == nil {
  		return errors.Errorf("dir must not be a valid ULID")
  	}
  
  	db.cmtx.Lock()
  	defer db.cmtx.Unlock()
  
  	db.mtx.RLock()
  	defer db.mtx.RUnlock()
  
  	for _, b := range db.blocks {
  		level.Info(db.logger).Log("msg", "snapshotting block", "block", b)
  
  		if err := b.Snapshot(dir); err != nil {
  			return errors.Wrapf(err, "error snapshotting block: %s", b.Dir())
  		}
  	}
  	if !withHead {
  		return nil
  	}
  	_, err := db.compactor.Write(dir, db.head, db.head.MinTime(), db.head.MaxTime(), nil)
  	return errors.Wrap(err, "snapshot head block")
  }
docs: // Snapshot writes the current data to the directory. If withHead is set to true it
  // will create a new block containing all data that's currently in the memory buffer/WAL.