Why Automate Backups?
Manual backups are unreliable. Automation ensures:- Consistency: Backups run on schedule, even when you forget
- Versioning: Multiple snapshots over time for point-in-time recovery
- Disaster recovery: Recent backups are always available
- Peace of mind: Set it and forget it
Test your automation thoroughly before relying on it. Verify backups are created and restorable.
Prerequisites
Before automating:-
Initialize your repository
-
Test manual backup
-
Test manual restore
Using Profiles for Automation (Recommended)
Profiles are the cleanest way to automate backups. Set up once, then your scripts only need the encryption password:1
Create a store with encryption
2
Create profiles for each source
3
Create a backup script
~/bin/backup.sh
4
Schedule with cron
Add or remove profiles from
profiles.yaml without touching the backup script. Use cloudstic backup -all-profiles and it picks up changes automatically.Setting Up Environment Variables
Store credentials in environment variables to avoid typing them repeatedly.Create a Configuration File
~/.cloudstic_env
Load Configuration
In your backup scripts:Automation with Cron (Linux/macOS)
Cron is the standard Unix job scheduler.Basic Cron Job
1
Create a backup script
Create Make it executable:
~/bin/backup.sh:2
Test the script
Run manually to verify:
3
Add to crontab
Edit your crontab:Add a cron entry:
4
Verify cron setup
List your cron jobs:Wait for the scheduled time and check logs:
Cron Schedule Examples
Automation with Systemd (Linux)
Systemd timers are a modern alternative to cron.Create a Systemd Service
1
Create service file
Create
~/.config/systemd/user/cloudstic-backup.service:2
Create timer file
Create
~/.config/systemd/user/cloudstic-backup.timer:3
Enable and start the timer
4
Verify timer status
5
Test the service manually
Trigger a backup immediately:
Systemd Timer Schedule Examples
Advanced Backup Script
A production-ready script with logging, error handling, and retention:~/bin/cloudstic-backup.sh
Monitoring and Alerting
Email Notifications on Failure
Send email when backups fail:~/bin/backup-with-email.sh
Install
mailutils or sendmail for the mail command:Health Check Pings
Use Healthchecks.io or similar services:Cloud-Specific Automation
AWS Lambda Backup
Run backups from Lambda (e.g., backing up EFS to S3):lambda_function.py
GitHub Actions Backup
Back up repositories to S3:.github/workflows/backup.yml
Backing Up Cloud Sources
Google Drive Automated Backup
~/bin/backup-gdrive.sh
OneDrive Automated Backup
~/bin/backup-onedrive.sh
For cloud sources, the first backup is slow (full scan). Subsequent backups use change APIs and are much faster.
Structured Errors and Exit Codes for Scripting
Scripts and monitoring systems need machine-readable failure information, not just prose. Cloudstic supports this with-json and a small, predictable set of exit codes.
Exit Codes
Check
$? after a run to distinguish “the backup failed” from “the backup was stopped,” which matters for alerting: a 130 from a deliberate service restart shouldn’t page anyone the way a 1 from a real backup failure should.
JSON Error Output
Pass-json to any command and, on failure, Cloudstic writes a single-line JSON object to stderr instead of a human-readable message:
-json writes the command’s normal structured result to stdout as before; the JSON error shape is specific to the failure path and always goes to stderr, so you can safely parse stdout and stderr independently.
-json also gets a structured error, with the same 130 exit code:
Troubleshooting Automated Backups
Cron Job Doesn’t Run
-
Check cron service is running:
-
Verify crontab syntax:
-
Check system logs:
-
Test script manually:
Environment Variables Not Loaded
Cron has a minimal environment. Always source your config file:Backup Fails Silently
Redirect output to a log file:StandardOutput and StandardError.
”Repository locked” Error
A previous backup may still be running or crashed without releasing the lock.Best Practices
1
Test automation before relying on it
Run manual backups and restores to verify the setup works.
2
Monitor backup success
Use health check services or email alerts.
3
Rotate logs
Delete old log files to save space:
4
Run periodic integrity checks
Add weekly
cloudstic check runs:5
Combine backup with retention
Clean up old snapshots automatically:
6
Document your setup
Keep notes on:
- Backup schedule
- Retention policy
- Storage credentials location
- Recovery procedure
Next Steps
Retention Policies
Manage automated snapshot lifecycle
Encryption Keys
Secure credentials for automated backups
Restoring Files
Test your automated backups
Check Command
Automate integrity verification