Basic Usage
Back up a remote directory via SFTP:Configuration Options
Required Flags
| Flag | Description | Environment Variable |
|---|---|---|
-source sftp://[user@]host[:port]/<path> | Specifies SFTP source with connection details | CLOUDSTIC_SOURCE |
Authentication Flags
| Flag | Description | Environment Variable |
|---|---|---|
-source-sftp-password <pw> | SSH password | CLOUDSTIC_SOURCE_SFTP_PASSWORD |
-source-sftp-key <path> | Path to SSH private key | CLOUDSTIC_SOURCE_SFTP_KEY |
-source-sftp-known-hosts <path> | Path to known_hosts file | CLOUDSTIC_SOURCE_SFTP_KNOWN_HOSTS |
-source-sftp-insecure | Skip host key validation (INSECURE) | CLOUDSTIC_SOURCE_SFTP_INSECURE |
Optional Flags
| Flag | Description |
|---|---|
-exclude <pattern> | Exclude pattern (gitignore syntax, repeatable) |
-exclude-file <path> | Load exclude patterns from file |
-tag <tag> | Tag to apply to the snapshot (repeatable) |
-dry-run | Scan source without writing to store |
Authentication Methods
Cloudstic supports three SSH authentication methods:1. Private Key (Recommended)
Use an SSH private key for authentication:2. Password
Use password authentication:3. SSH Agent (Automatic)
IfSSH_AUTH_SOCK is set, Cloudstic automatically uses your SSH agent:
Examples
Backup Web Server
Back up a web server’s document root:Backup with Custom Port
Connect to a non-standard SSH port:Backup with Exclusions
Exclude cache and temporary files:Multiple Server Backups
Back up multiple servers sequentially:How It Works
Connection Process
Authenticate
Authentication is attempted in order:
- Private key (if specified)
- Password (if specified)
- SSH agent (if available)
Walk directory tree
The remote directory is recursively scanned. File permissions (mode bits) and numeric ownership (uid/gid) are captured from the SFTPv3
ATTRS response. Birth time, file flags, and extended attributes are not available over SFTP.File Identification
SFTP files are identified by their relative path from the source root:- Source path:
/home/user/data - File:
/home/user/data/reports/Q1.pdf - File ID:
reports/Q1.pdf
Source Information
Each snapshot records:- Type:
sftp - Account:
user@host(e.g.,deploy@web-server.com) - Path: Remote directory path (e.g.,
/var/www/html)
Security Considerations
SSH Host Key Verification
By default, Cloudstic strictly validates the remote server’s SSH host key against your localknown_hosts file (defaulting to ~/.ssh/known_hosts). If the host key is not found or does not match, the connection will fail.
For production use, you should ensure the server’s host key is present in your known_hosts file. You can add it using ssh-keyscan:
Custom known_hosts file
If your environment uses a non-standard location for known hosts, use the-source-sftp-known-hosts flag:
Insecure Mode (Not Recommended)
To skip host key verification entirely (e.g. for initial testing or internal networks where you trust the route), use the-source-sftp-insecure flag:
Credential Management
Best practices for managing SFTP credentials:Performance Considerations
Network Overhead
SFTP backups are slower than local backups due to:- Network latency
- SSH encryption overhead
- Remote filesystem access
Typical Performance
- Small files: 100-500 files/second
- Large files: Limited by network bandwidth
- Network: 10-100 MB/s depending on connection
Optimizing SFTP Backups
Common Use Cases
Web Server Backups
Database Server Backups
Application Server Backups
Troubleshooting
Connection Refused
- Check that SSH service is running on the remote server
- Verify the hostname and port are correct
- Check firewall rules
Authentication Failed
- Verify username and credentials
- Check SSH key permissions (must be 600)
- Ensure the public key is in
~/.ssh/authorized_keyson the server - Try password authentication if key auth fails
Permission Denied
- Check that the user has read access to the source directory
- Verify the source path is correct
- Check filesystem permissions on the remote server
Slow Backups
If SFTP backups are taking too long:- Use exclude patterns to reduce data transfer
- Check network bandwidth between source and destination
- Consider local backups if possible (install Cloudstic on the remote server)
- Run backups during off-peak hours
Environment Variables
Set default SFTP credentials:Next Steps
Local Source
Learn about backing up local directories
SSH Key Setup
Set up SSH keys for authentication
Scheduling Backups
Automate backups with cron or systemd
Exclude Patterns
Master exclude pattern syntax