`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)
lxc file pull my-instance/var/log/app.log .
LXD Host
Your physical machine or server
Practical Usage Examples
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 .
/etc/nginx/nginx.conf
./nginx.conf
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
/var/log/app/
~/app_logs/app/
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
/var/backups/latest.sql
~/db_backup_today.sql