Backs up a NAS configuration directory to Google Drive on a nightly schedule using rclone. Backups are organized into daily, weekly (Sundays), and monthly (1st of month) folders with automatic pruning of old copies. Errors are logged and optionally pushed as Pushover notifications.
rclone(configured with a Google Drive remote)zipcurl
All configuration is supplied via environment variables, sourced from /etc/nas-backup.env by the systemd service.
-
Copy the example file and fill in your values:
sudo cp nas-backup.env.example /etc/nas-backup.env sudo chmod 600 /etc/nas-backup.env sudo nano /etc/nas-backup.env
-
Required variables:
NAS_CONFIG_DIR— absolute path to the directory to back upGDRIVE_DEST— rclone destination (e.g.gdrive:backups)
-
Optional variables:
RCLONE_CONFIG— path torclone.conf(defaults to/root/.config/rclone/rclone.conf). The service runs as root and systemd does not setHOME, so rclone cannot locate its config by the usual~/.configpath.PUSHOVER_TOKEN— for Pushover failure alertsPUSHOVER_USER— for Pushover failure alerts
# Install the script
sudo cp nas-backup.sh /usr/local/bin/nas-backup.sh
sudo chmod 755 /usr/local/bin/nas-backup.sh
# Install the systemd units (ExecStart expects /usr/local/bin/nas-backup.sh)
sudo cp nas-backup.service nas-backup.timer /etc/systemd/system/
sudo systemctl daemon-reload
# Enable and start the nightly timer
sudo systemctl enable --now nas-backup.timer| Tier | Frequency | Pruned after |
|---|---|---|
| Daily | Every run | 7 days |
| Weekly | Sundays | 28 days |
| Monthly | 1st of each month | Never |
Errors go to stderr and are captured by journald:
journalctl -u nas-backup -n 50
journalctl -u nas-backup -fsudo systemctl start nas-backup