Skip to main content
This guide shows you how to automate Cloudstic backups using cron jobs, systemd timers, and other scheduling tools.

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:
  1. Initialize your repository
  2. Test manual backup
  3. Test manual restore
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
Make it executable:
4

Schedule with cron

Use --no-prompt in automation scripts to ensure commands never hang waiting for interactive input. Missing credentials will cause a clear error instead.
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
Secure the file:
Never commit this file to version control. Add it to .gitignore if your home directory is tracked.

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 ~/bin/backup.sh:
Make it executable:
2

Test the script

Run manually to verify:
3

Add to crontab

Edit your crontab:
Add a cron entry:
Use absolute paths in cron jobs. Avoid ~ or relative paths.
4

Verify cron setup

List your cron jobs:
Wait for the scheduled time and check logs:

Cron Schedule Examples

Use crontab.guru to test cron expressions.

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:
Persistent=true ensures missed runs execute on next boot.
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
Make it executable:

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
Package Cloudstic in a Lambda layer and schedule with EventBridge.

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:
On success, -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.
An interrupted run with -json also gets a structured error, with the same 130 exit code:
Combine -json with the exit code check above in monitoring scripts: use the exit code to decide whether to alert, and the JSON error field to say why.

Troubleshooting Automated Backups

Cron Job Doesn’t Run

  1. Check cron service is running:
  2. Verify crontab syntax:
  3. Check system logs:
  4. Test script manually:

Environment Variables Not Loaded

Cron has a minimal environment. Always source your config file:
Or set variables directly in the script:

Backup Fails Silently

Redirect output to a log file:
Or use systemd with StandardOutput and StandardError.

”Repository locked” Error

A previous backup may still be running or crashed without releasing the lock.
Prevent overlapping runs in your script:

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