Backup helper script for Synology NAS

A simple backup helper script for Synology NAS that copies a Hyper Backup file or folder from a fixed source path to an external USB-mounted destination, then sends an email notification about the result.

copy2usb.sh

Backup helper script for Synology NAS

What it does

  • Verifies the source backup path exists before attempting to copy.
  • Verifies the destination USB mount path exists and is reachable.
  • Copies the source to the destination using cp -rf.
  • Checks whether the destination copy exists after a successful cp.
  • Sends an email notification for success, warning, or failure.

Script functions

send_mail()

This helper function builds a simple email message with headers and body text, then pipes it into /bin/ssmtp.

  • From: configured by MAIL_FROM
  • To: configured by MAIL_TO
  • Subject: set according to success or failure state
  • Date: uses the current date in RFC 2822 format

Configuration

Edit the top of copy2usb.sh to match your environment:

  • SRC – source file or directory to copy
  • DST – destination directory mounted from the USB drive
  • SMTP – SMTP server address used by ssmtp (in this script the variable is defined but not directly used by send_mail)
  • MAIL_TO – destination email address for notifications
  • MAIL_FROM – sender email address used in the notification header

Example: configurtion for sSMTP server using the backup script on Synology NAS:

vi /etc/ssmtp/ssmtp.conf

Minimum content for the SMTP gateway without authentication:

SRC="/volume1/data/DS918_1.hbk"
DST="/volumeUSB1/usbshare/"
SMTP="203.0.113.104"
MAIL_TO="hostmaster@example.com"
MAIL_FROM="nas@ds918.local"

Usage

  1. Testing the sSMTP configuration with email sending can be done with this command.
echo -e "From: nas@ds918.local\nTo: hostmaster@example.com\nSubject: Test\n\nTest von DS918" | /bin/ssmtp hostmaster@example.com
  1. Make sure the script is executable:
chmod +x copy2usb.sh
  1. Run the script manually:
./copy2usb.sh
  1. Optionally schedule it with cron or Synology Task Scheduler to run regularly.

A task is created in the DSM Task Scheduler, Go to Control Panel > Task Scheduler.

Expected behavior

  • If the source path does not exist, the script exits with code 1 and sends a failure email.
  • If the destination USB mount is not reachable, it exits with code 2 and sends a failure email.
  • If the copy command returns success but the copied destination is not verifiable, it sends a warning email.
  • If the copy succeeds and the destination file or folder exists, it sends a success email.

Requirements

  • bash
  • cp
  • ssmtp configured and available at /bin/ssmtp

Notes

  • The script currently uses cp -rf, which overwrites existing files and copies recursively.
  • The SMTP variable is defined for configuration consistency, but send_mail() relies on the /bin/ssmtp command and does not directly use the variable in this version.

Use Chrome Secure DNS

If you want to use Secure DNS in Google Chrome, and the computer is in a Windows domain, the following information appears: This setting is managed by your administrator !!

Use Chrome Secure DNS

In Google Chrome settings, the “Use secure DNS” option cannot be enabled; the slider on the right is inactive (grayed out). This occurs when the computer belongs to an organization and is part of a Windows domain. A pop-up window appears above the icon stating that this setting is managed by your administrator.

The “Use secure DNS” setting can still be enabled. To do this, two registry keys need to be added. Open a command prompt as administrator and run the following lines using copy and paste.

REG ADD "HKLM\SOFTWARE\Policies\Google\Chrome" /v "DnsOverHttpsMode" /t REG_SZ /d "automatic" /f
REG ADD "HKLM\SOFTWARE\Policies\Google\Chrome" /v "DnsOverHttpsTemplates" /t REG_SZ /d "https://cloudflare-dns.com/dns-query https://dns.google/dns-query" /f

After adding the registry keys, Chrome needs to be restarted; the DNS settings will still not be displayed, but will be applied by Chrome.

How can I verify “Chrome Secure DNS” ?

In the Chrome address bar type chrome://net-internals/#dns and press Enter. Now enter URL in the Domain field, e.g., news.google.com and click Lookup.

This should display output similar to the following::

Resolved IP addresses of “news.google.com”: [“142.250.204.142”].
No alternative endpoints.

quote Also helpful and possibly necessary is clearing the host cache, and possibly flushing socket pools under Sockets.

In managed organizations, Google Chrome may still need to be checked for policies, using the URL chrome://policy/#dns

What is Secure DNS?

Secure DNS (Domain Name System) is a service that protects your internet traffic by encrypting DNS queries and filtering out malicious websites. It prevents third parties, such as Internet Service Providers (ISPs), from tracking your browsing habits and safeguards against redirection to phishing sites. The primary technologies are DNS over HTTPS (DoH) or DNS over TLS (DoT).