copy
Copy files and directories between targets (local, SSH hosts, Docker containers, Kubernetes pods).
Synopsisβ
xec copy [options] <source> <destination>
xec cp [options] <source> <destination> # Alias
Descriptionβ
The copy
command transfers files and directories between different targets in your Xec environment. It supports copying between any combination of local filesystem, SSH hosts, Docker containers, and Kubernetes pods.
Argumentsβ
<source>
- Source path in format[target:]path
<destination>
- Destination path in format[target:]path
Path Formatβ
Paths can be specified as:
path
- Local path (relative or absolute)local:path
- Explicit local pathhosts.name:path
- SSH host pathcontainers.name:path
- Docker container pathpods.name:path
- Kubernetes pod path
Optionsβ
General Optionsβ
-p, --profile <profile>
- Configuration profile to use-i, --interactive
- Interactive mode for selecting files and options-r, --recursive
- Copy directories recursively--preserve
- Preserve file attributes (timestamps, permissions)-f, --force
- Force overwrite of existing files--parallel
- Copy multiple files in parallel--max-concurrent <n>
- Maximum concurrent copy operations (default: 4)-v, --verbose
- Enable verbose output-q, --quiet
- Suppress output--dry-run
- Preview copy operations without executing
Examplesβ
Basic File Copyβ
Copy a single file from local to remote:
# Copy file to SSH host
xec copy ./config.json hosts.web-server:/etc/app/config.json
# Copy file from Docker container
xec copy containers.app:/app/data.csv ./backup/data.csv
# Copy file from Kubernetes pod
xec copy pods.database:/var/lib/mysql/backup.sql ./backups/
Directory Copyβ
Copy entire directories with -r
flag:
# Copy directory to Docker container
xec copy -r ./src containers.app:/app/src
# Copy directory from SSH host
xec copy -r hosts.backup:/var/backups/ ./local-backups/
# Copy with attribute preservation
xec copy -r --preserve ./build/ hosts.prod:/var/www/html/
Multiple Targetsβ
Copy from/to multiple targets using wildcards:
# Copy from all containers
xec copy containers.*:/app/config.json ./configs/{name}.json
# Copy to multiple SSH hosts
xec copy ./deploy.sh hosts.web-*:/tmp/deploy.sh
# Copy between multiple targets
xec copy containers.app:/data/* hosts.backup:/backup/app/
Cross-Target Copyβ
Copy directly between different target types:
# From Docker to SSH
xec copy containers.db:/backup.sql hosts.backup:/var/backups/
# From SSH to Kubernetes
xec copy hosts.source:/data/* pods.processor:/input/
# From Kubernetes to Docker
xec copy pods.app:/logs/* containers.logstash:/data/
Advanced Usageβ
# Interactive mode - prompts for options
xec copy -i
# Parallel copy with concurrency limit
xec copy --parallel --max-concurrent 8 ./files/* hosts.storage:/data/
# Force overwrite existing files
xec copy -f ./config.new hosts.*:/etc/app/config.json
# Dry run to preview operations
xec copy --dry-run -r ./dist/ containers.app:/app/
Patterns and Wildcardsβ
The copy command supports various pattern matching:
*
- Match any characters?
- Match single character{a,b,c}
- Brace expansion**
- Recursive match (when used in paths)
# Copy all log files
xec copy hosts.server:/var/log/*.log ./logs/
# Copy specific file types
xec copy ./src/**/*.js containers.app:/app/src/
# Copy from multiple specific targets
xec copy {hosts.web1,hosts.web2}:/etc/nginx/nginx.conf ./configs/
Target Resolutionβ
Targets are resolved from your .xec/config.yaml
:
targets:
hosts:
web-server:
type: ssh
host: 192.168.1.100
username: deploy
containers:
app:
type: docker
container: my-app
pods:
database:
type: k8s
namespace: default
pod: mysql-abc123
Performance Considerationsβ
- Use
--parallel
for multiple file operations - Adjust
--max-concurrent
based on network capacity - Large files are streamed, not loaded into memory
- Progress indication shown for long operations
Error Handlingβ
The command handles common errors gracefully:
- Source file not found
- Destination permission denied
- Network connectivity issues
- Target not accessible
- Disk space issues
Use -v, --verbose
for detailed error information.
Security Notesβ
- SSH key authentication preferred over passwords
- File permissions preserved with
--preserve
- Temporary files cleaned up on failure
- Sensitive data not logged in verbose mode
Related Commandsβ
- on - Execute commands on SSH hosts
- in - Execute commands in containers/pods
- watch - Watch files for changes
Configurationβ
Command defaults can be set in .xec/config.yaml
:
commands:
copy:
recursive: true
preserve: true
maxConcurrent: 8
Exit Codesβ
0
- Success1
- General error2
- Invalid arguments3
- Source not found4
- Destination error5
- Network error