DEV Community

Xavier Rey-Robert
Xavier Rey-Robert

Posted on • Updated on

Effortlessly Exporting and Importing Podman Volumes Across Hosts

Effortlessly Exporting and Importing Podman Volumes Across Hosts

Hey folks, let's tackle a common hiccup in managing Podman volumes remotely. If you've tried using podman volume export with a remote Podman client, you've likely noticed it's not directly supported. But, I've crafted a workaround that simplifies the process.

Image description

The Challenge

Working remotely and need to move a Podman volume from one server to another? You'll quickly find that podman volume export isn't designed for remote client operations.

The Workaround

The solution lies in two Bash scripts that utilize SSH, SCP, and Podman's capabilities to facilitate volume export and import across remote hosts.

Exporting Volumes Made Simple

The podman_remote_volume_export.sh script connects to your remote host via SSH, exports the specified Podman volume to a tarball, and then SCPs this tarball back to your local machine. It's a straightforward way to get your volume data where you need it.

Importing as easy

The podman_remote_volume_import.sh script then takes over, uploading the exported tarball to a different remote host. It checks for existing volumes (offering an option to overwrite) and imports the volume data efficiently.

A Few Considerations

  • Safety Checks: To prevent accidental data loss, there's a prompt for confirmation before overwriting existing volumes during the import process.
  • Clean as We Go: Both scripts clean up after themselves, removing temporary tarballs to keep your hosts tidy.

Usage

To run these scripts:

./podman_remote_volume_export.sh user@remotehost volume_name
./podman_remote_volume_import.sh user@remotehost new_volume_name /path/to/archive.tar
Enter fullscreen mode Exit fullscreen mode

The Bottom Line

The podman volume export limitation for remote operations can be circumvented with these scripts, streamlining the process of migrating volumes. Designed for developers familiar with container management, they offer a practical solution to a common problem.

CODE

For a closer look and potential customization, the scripts are available on Gist: Podman Volume Management Scripts Gist.

Happy containerizing!

Edit 02/19/24:
Just added podman_remote_volume_migrate.sh to do one or multiple volumes in one shot...

podman_remote_volume_migrate.sh
Usage: /Volumes/UsersData_Macos/Users/xav/scripts/podman_remote_volume_migrate.sh <SOURCE_HOST> <DESTINATION_HOST> <VOLUME_NAME>...
Enter fullscreen mode Exit fullscreen mode

Top comments (0)