Backup Manager store its backups archives on the local disk. To prevent data loss in case of hardware failure, it is recommended to create a backup copy of the archives on a remote host. This post describe how to setup Backup Manager to copy its archives to a remote host with scp.
This howto is tested on:
- Debian 10.0 Buster
Requirements
This howto requires:
- Backup Manager, as described by Install Backup Manager on Debian.
- A remote SFTP server, as described by Setup a SFTP server on Debian.
Settings
Initialize the settings associative array:
declare -A bmSettings
Set the remote user account:
bmSettings['BM_UPLOAD_SSH_USER']='bmngr'
Set the remote host addresses:
bmSettings['BM_UPLOAD_SSH_HOSTS']='server.domain.com'
Set the remote host SSH port (22 by default):
bmSettings['BM_UPLOAD_SSH_PORT']='22'
Set the remote host path where the backup will be stored:
bmSettings['BM_UPLOAD_SSH_DESTINATION']='/var/archives'
Enable the purge of old backup data:
bmSettings['BM_UPLOAD_SSH_PURGE']='true'
Set the TTL (time to live) of the backup data on the remote server (in days):
bmSettings['BM_UPLOAD_SSH_TTL']='30'
Configuration
Detect if sudo is available (“command” is used if not):
cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'
Set the SSH key to be used to log-in on the remote host:
bmSettings['BM_UPLOAD_SSH_KEY']='/etc/backup-manager/id_rsa'
Create the folder containing Backup Manager SSH key pair:
${cmdProxy} mkdir --parent "$(command dirname "${bmSettings['BM_UPLOAD_SSH_KEY']}")"
Create a SSH key pair with a blank password for Backup Manager:
if [ ! -e "${bmSettings['BM_UPLOAD_SSH_KEY']}" ]; then
${cmdProxy} ssh-keygen -t rsa -N '' -f "${bmSettings['BM_UPLOAD_SSH_KEY']}"
fi
Register the public key on the remote SSH server account:
${cmdProxy} ssh-copy-id -i "${bmSettings['BM_UPLOAD_SSH_KEY']}.pub" -p "${bmSettings['BM_UPLOAD_SSH_PORT']}" \
"${bmSettings['BM_UPLOAD_SSH_USER']}@${bmSettings['BM_UPLOAD_SSH_HOSTS']}"
Fetch current backup upload methods:
IFS=' ' read -r -a 'backupUploadMethods' \
<<< "$(${cmdProxy} grep '^export BM_UPLOAD_METHOD=' '/etc/backup-manager.conf' \
| command sed -e 's/^[^=]*="\(.*\)".*$/\1/')"
Remove “none” and “scp” from existing backup upload methods:
declare -a removedMethods
removedMethods=( 'none' 'scp' )
for removedMethod in "${removedMethods[@]}"; do
for index in "${!backupUploadMethods[@]}"; do
[[ "${backupUploadMethods[index]}" = "${removedMethod}" ]] && unset 'backupUploadMethods[index]'
done
done
Add “scp” to backup upload methods:
backupUploadMethods+=( 'scp' )
Update backup upload method setting:
IFS=' ' bmSettings['BM_UPLOAD_METHOD']="${backupUploadMethods[*]}"
Apply the settings:
declare -a sedOptions
sedOptions=()
for settingName in ${!bmSettings[@]}; do
sedOptions+=( '-e' "s|[#]*\(.*${settingName}=\).*$|\1\"${bmSettings["${settingName}"]}\"|" )
done
${cmdProxy} sed -i "${sedOptions[@]}" '/etc/backup-manager.conf'
0 Comments