mirror of
https://github.com/siderolabs/talos.git
synced 2025-09-02 12:31:12 +02:00
Actual API is implemented in the `init`, as it has access to root filesystem. `osd` proxies API back to `init` with some tricks to support grpc streaming. Given some absolute path, `init` produces and streams back .tar.gz archive with filesystem contents. `osctl cp` works in two modes. First mode streams data to stdout, so that we can do e.g.: `osctl cp /etc - | tar tz`. Second mode extracts archive to specified location, dropping ownership info and adjusting permissions a bit. Timestamps are not preserved. If full dump with owner/permisisons is required, it's better to stream data to `tar xz`, for quick and dirty look into filesystem contents under unprivileged user it's easier to use in-place extraction. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
36 lines
782 B
Go
36 lines
782 B
Go
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
// Package archiver provides a service to archive part of the filesystem into tar archive
|
|
package archiver
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"context"
|
|
"io"
|
|
)
|
|
|
|
// TarGz produces .tar.gz archive of filesystem starting at rootPath
|
|
func TarGz(ctx context.Context, rootPath string, output io.Writer) error {
|
|
paths, errCh, err := Walker(ctx, rootPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
zw := gzip.NewWriter(output)
|
|
//nolint: errcheck
|
|
defer zw.Close()
|
|
|
|
err = Tar(ctx, paths, zw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = <-errCh; err != nil {
|
|
return err
|
|
}
|
|
|
|
return zw.Close()
|
|
}
|