HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: //usr/syno/sbin/system_restore.sh
#!/bin/sh

. /usr/syno/share/environments.sh
. /usr/syno/share/dsmupdate/dsmupdate.subr
. /usr/syno/share/projectquota.sh
. /usr/syno/share/rootdevice.sh

RootMnt="$1"
RestoreFromABB="$RootMnt/.restore_from_abb"
RestoreFromHBED="$RootMnt/.restore_from_hbed"

if [ ! -f "$RestoreFromABB" ] && [ ! -f "$RestoreFromHBED" ] ; then
	return 0
fi

CleanLocalConf()
{
	Echo "clean local unuse conf for system recovery before restore"

	# workaround for /var/log corsslink(project quota)
	CleanupEvenIfAppendOnlyOrImmutable "$RootMnt/var/log"
	Rm -rf "$CustomConfigsDir/var/log/synolog"

	# remove original preference (which should be recover)
	# Notice: preference might by a symlink to volume in DSM7. In this case, we will remove the link too
	Rm -rf "$RootMnt/usr/syno/etc/preference"
}

ProcessCustomConfigs() # src dest
{
	ConfigSrc="$1"
	ConfigDest="$2"

	Mkdir -p "$ConfigDest"
	for config in $CustomConfigsList; do
		ConfigDir=$(/bin/dirname "$config")
		Mkdir -p "$ConfigDest/$ConfigDir"
		Cp -af "$ConfigSrc/$config" "$ConfigDest/$ConfigDir"
	done
	return 0
}

Echo "Start to restore system config"
CustomConfigsList="/var/lib/brm/selected_task /var/lib/hbed/selected_task /usr/syno/etc/juniormodedata /var/log"
CustomConfigsDir="$RootMnt/.backup_process"

Echo "backup custom-configs for system recovery"
ProcessCustomConfigs "$RootMnt" "$CustomConfigsDir"

Echo "clean conf"
CleanLocalConf

Echo "restore configs..."
RestoreConfig "$RootMnt" "$RootMnt" "$(IsBtrfsRootFs && echo "no" || echo "yes" )"

Echo "restore custom-configs for system recovery"
ProcessCustomConfigs "$CustomConfigsDir" "$RootMnt"
Rm -rf "$CustomConfigsDir"

# might be useless code
if [ -d ${RootMnt}/.SynoUpgradePackages.brm ]; then
	Echo "repair built-in packages for partition layout changed"
	Rm -rvf ${RootMnt}/.SynoUpgradePackages
	Mv -v ${RootMnt}/.SynoUpgradePackages.brm ${RootMnt}/.SynoUpgradePackages
fi

# run configupdater for different model / version
/bin/touch "$RootMnt/var/.UpgradeBootup"
/bin/touch "$RootMnt/.updater"
/bin/touch "$RootMnt/.recovery_bootup"
Rm -f "$RestoreFromABB"
Rm -f "$RestoreFromHBED"
# Reassure project ID is set on /var/log after manipulations on rootfs.
if PQMounted "${RootMnt}" ; then
	touch "${RootMnt}/.project.var.log"
fi
Echo "Finish to restore system config from ActiveBackup"

return 0