What is `lxc file pull`?

The ultimate guide to securely and efficiently transferring files from an LXD instance to the host.

`lxc file pull` is a core LXD command-line tool that allows you to "pull" files or entire directories from a running container or virtual machine instance to your LXD host. This is an extremely useful feature as it provides a simple, secure way to transfer files locally without needing extra configuration like SSH.

Why Choose `lxc file pull`?

Simple & Direct

No need to configure SSH keys or network services. Transfer files with a single command.

Secure & Reliable

All transfers are handled through the LXD daemon's secure API, ensuring data safety.

Powerful

Supports not only single files but also easily pulls entire directory structures with the recursive option.

Easy to Script

Perfect for integration into backup, deployment, or automated operations scripts.

Syntax Breakdown

lxc file pull <instance_name>/<path_inside> [<instance_name>/<path_inside>...] <local_destination_path>

`<instance_name>/<path_inside>`

The source file path. Consists of the instance name and the absolute path within the instance, e.g., `my-ubuntu/etc/hosts`.

`[...]`

Optional part. You can specify multiple source files at once to pull them all into the destination directory.

`<local_destination_path>`

The destination path. This is where the file will be saved on the LXD host. It can be a directory or a new filename.

Workflow Diagram

LXD Instance

(Container or VM)

Source File: /var/log/app.log
lxc file pull my-instance/var/log/app.log .

LXD Host

Your physical machine or server

Destination File: ./app.log

Practical Usage Examples

Example 1

Pulling a Single Configuration File

Suppose you need to inspect the Nginx configuration file from the `web-server` instance. You can pull it directly into your current directory (represented by `.`).

lxc file pull web-server/etc/nginx/nginx.conf .
web-server:
/etc/nginx/nginx.conf
host:
./nginx.conf
Example 2

Recursively Pulling an Entire Log Directory

When you need to analyze an entire log directory, use the `-r` or `--recursive` flag. This will copy the entire `/var/log/app` directory from the `api-server` instance to the `~/app_logs` directory on the host.

lxc file pull -r api-server/var/log/app ~/app_logs
api-server:
/var/log/app/
host:
~/app_logs/app/
Example 3

Pulling and Renaming a File

You can specify a full file path as the destination to rename the file while pulling it. Here, we pull the backup file from the `database` instance and name it `db_backup_today.sql`.

lxc file pull database/var/backups/latest.sql ~/db_backup_today.sql
database:
/var/backups/latest.sql
host:
~/db_backup_today.sql