plash export-tar
Usage
plash export-tar CONTAINER [ FILE | - ]
Description
Export container as tar archive. It exports the file system of a container
to the given file as a compressed tar archive. If no file is supplied or the
file is '-' the tar archive wil be printed to stdout instead.
Tested Behaviour
#!/bin/bash
set -xeu
• tar written to file in first argument
tmp=$(mktemp)
plash export-tar 1 $tmp
tar --list -f $tmp >/dev/null
• tar printed to stdout if no arguments
tmp=$(mktemp)
plash export-tar 1 > $tmp
tar --list -f $tmp >/dev/null
• tar printed to stdout if `-` is the first argument
tmp=$(mktemp)
plash export-tar 1 - > $tmp
tar --list -f $tmp >/dev/null
• exported tar looks like a rootfs
tmp=$(mktemp)
plash export-tar 1 > $tmp
tar --list -f $tmp | grep /etc/passwd
tar --list -f $tmp | grep /bin/sh
Source Code
#define USAGE "usage: plash export-tar CONTAINER [ FILE | - ]\n"
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <plash.h>
int export_tar_main(int argc, char *argv[]) {
char *image_id, *file;
if (!(image_id = argv[1])) {
fputs(USAGE, stderr);
return EXIT_FAILURE;
}
if (!(file = argv[2]))
file = "-";
pl_unshare_user();
execvp("/proc/self/exe", (char *[]){"plash", "with-mount", image_id, "tar",
"-cf", file, ".", NULL});
pl_fatal("exec");
return EXIT_FAILURE;
}