Disclaimer: These are personal scripts shared as a reference example. They are provided as-is, without any warranty. Use at your own risk. Paths, hostnames, dataset names and other settings are hardcoded for a specific setup - you will need to adapt them to your own environment before use.
A set of shell scripts for automated backups on a FreeBSD-based NAS.
The system performs the following steps in order:
- Configuration validation - checks all config files, include/exclude lists, ZFS datasets and rclone remotes before doing anything
- WordPress backup - archives site files with
tarand dumps databases withmysqldump - VictoriaMetrics backup - daily incremental backups via
vmbackup, weekly full copies - rsync from remote hosts - pulls data from hosts defined in
hosts.conf, runs dry-run first, creates a ZFS snapshot after each successful sync - ZFS snapshot cleanup - removes snapshots older than 30 days
- rclone sync - pushes data to cloud remotes defined in
rclone-remotes.conf, moved/deleted files go to_archive/instead of being deleted
Alerts are sent via ntfy.sh on failures and on completion summary.
.
├── backup.sh # main orchestrator script
├── validate-config.sh # pre-flight config validation
├── vmbackup-backup.sh # VictoriaMetrics backup
├── web-backup.sh # WordPress files + database backup
├── config/
│ ├── hosts.conf # rsync hosts configuration
│ └── rclone-remotes.conf # ZFS dataset -> rclone remote mapping
├── includes/ # per-host rsync include lists
└── excludes/ # per-host rsync exclude lists
Pipe-separated list of hosts for rsync backups:
# hostname|user|include_file|exclude_file|destination|delete
myhost|root|myhost.include|global.exclude|/nas/backups/myhost|delete=no
Pipe-separated mapping of ZFS datasets to rclone remotes:
# dataset|remote
tank/backups|my-gdrive
rsyncrclone(configured with at least one remote)vmbackup(for VictoriaMetrics backups)- ZFS
curl(for ntfy.sh alerts)/root/ntfy.token- file with ntfy.sh Bearer token
# validate config only
/opt/nas_backup/validate-config.sh
# run full backup
/opt/nas_backup/backup.shTypically scheduled via cron:
0 2 * * * /opt/nas_backup/backup.sh