Skip to content

setevoy2/nas-backup

Repository files navigation

NAS Backup Scripts

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.

Overview

The system performs the following steps in order:

  1. Configuration validation - checks all config files, include/exclude lists, ZFS datasets and rclone remotes before doing anything
  2. WordPress backup - archives site files with tar and dumps databases with mysqldump
  3. VictoriaMetrics backup - daily incremental backups via vmbackup, weekly full copies
  4. rsync from remote hosts - pulls data from hosts defined in hosts.conf, runs dry-run first, creates a ZFS snapshot after each successful sync
  5. ZFS snapshot cleanup - removes snapshots older than 30 days
  6. 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.

Structure

.
├── 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

Configuration

hosts.conf

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

rclone-remotes.conf

Pipe-separated mapping of ZFS datasets to rclone remotes:

# dataset|remote
tank/backups|my-gdrive

Requirements

  • rsync
  • rclone (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

Usage

# validate config only
/opt/nas_backup/validate-config.sh

# run full backup
/opt/nas_backup/backup.sh

Typically scheduled via cron:

0 2 * * * /opt/nas_backup/backup.sh

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages