Skip to content

Instantly share code, notes, and snippets.

@alainwolf
Last active January 11, 2023 16:05
Show Gist options
  • Save alainwolf/5a305e505b46b13740aa3bb239342f3d to your computer and use it in GitHub Desktop.
Save alainwolf/5a305e505b46b13740aa3bb239342f3d to your computer and use it in GitHub Desktop.
Synology DiskStation configuration backup
#!/bin/ash
#
# Synology DiskStation configuration backup
# Must be run as root
# Tested on
# DSM 6.1.6-15266 Update 1 - MARVELL Armada XP MV78230 (DS214+)
#
# Author: Alain Wolf <alain@alainwolf.ch> - https://gist.github.com/alainwolf/
# Date/Version: 2018-04-22/1.5
#
# Abort on errors
set -e
#
# Filename of the configuration backup
FILE_NAME="$( hostname )"
#
# OpenPGP key ID for encryption (must be already present in keyring)
PGP_KEYID="0x0123456789ABCDEF"
#
# Where to store the encrypted configuration backup file
TARGET_DIR="/volume1/NetBackup/$( hostname )/SynologyDS"
#
# GnuPG Home Directory of the user runnung this script
GNUPGHOME="/root/.gnupg"
#
# --- Do not change anything below this line! ---
#
backup_file="${FILE_NAME}_$( date +%F_%H-%M-%S-%Z ).dss"
temp_dir=$(mktemp --directory )
echo
echo "Starting backup of Synology DiskStation configuration on $( hostname )"
echo
# Tell the Synology DiskStation to create a configuration backup
/usr/syno/bin/synoconfbkp export --filepath="${temp_dir}/${backup_file}"
#echo "Synology DiskStation configuration exported to ${backup_file} on ${SOURCE_HOST}."
# Encrypt
echo "Encrypting archive with OpenPGP key ${PGP_KEYID}"
gpg --homedir ${GNUPGHOME} --batch --trust-model always --recipient ${PGP_KEYID} \
--output "${TARGET_DIR}/${backup_file}.pgp" \
--encrypt "${temp_dir}/${backup_file}"
echo "Encrypted file saved to ${TARGET_DIR}/${backup_file}.pgp"
# Clean up
echo "Cleaning up ${temp_dir}."
rm -rf "${temp_dir}"
# Success
echo
echo "Backup completed. Have a nice day."
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment