Add support for remote backup server.

This commit is contained in:
Christoph 2018-12-02 21:46:09 +01:00
parent b8522b35f9
commit bb32613273
3 changed files with 98 additions and 45 deletions

View File

@ -11,7 +11,7 @@
filesystem=`df`
label=`tune2fs -l $backup_partition | grep -e "Filesystem volume name:" | awk '{print$4}'`
#label=`tune2fs -l $backup_partition | grep -e "Filesystem volume name:" | awk '{print$4}'`
#label="Root filesystem - /backup"
content_type='Content-Type: text/plain;\n charset="utf-8"'
@ -34,7 +34,7 @@
datum=`date +"%d.%m.%Y"`
echo -e "To:${admin_email}\n${content_type}\nSubject:Backup $company -- $datum\n$filesystem\n\ndisk label: $label\n$durations\n\n$send\n" | /usr/sbin/sendmail -F "BACKUP $company" -f $from_address $admin_email
echo -e "To:${admin_email}\n${content_type}\nSubject:Backup $company -- $datum\n$filesystem\n\nBackup resource / Label: $label\n$durations\n\n$send\n" | /usr/sbin/sendmail -F "BACKUP $company" -f $from_address $admin_email
if [[ -n "$extra_admin_email" ]]; then
echo -e "To:${extra_admin_email}\n${content_type}\nSubject:Backup $company -- $datum\n$filesystem\n\ndisk label: $label\n$durations\n\n$send\n" | /usr/sbin/sendmail -F "BACKUP $company" -f $from_address $extra_admin_email
fi
@ -47,7 +47,7 @@
err_msg="`grep -A 2 -B 1 -e\"\[ERROR\" $logFile`\n"
warn_msg="`grep -A 2 -B 2 -e\"\[WARN\" $logFile`\n"
msg_top="Backup $company vom $datum.\nBackupprozess (disk label: $label) beendet mit:"
msg_top="Backup $company vom $datum.\nBackup resource / Label: $label\nBackupprozess beendet mit:"
msg_body_01="\t$error Error(s)\n\t$warning Warning(s)\n"
msg_body_02="\n\n--- ERROR(S) ---\n${err_msg}\n\n--- WARNING(S) ...\n${warn_msg}"

View File

@ -47,6 +47,12 @@ hosts_base_dir=$crontab_base_dir/hosts
extern_usb_disk=false
extern_sata_disk=false
intern_disk=false
# - remote_disk
# -
# - - You need a fstab-entry in order to mount the backup partition
# - - Configure 'backup_mountpoint'
# -
remote_disk=true
## - if backup partion cannot be determined, try this one..
## -
@ -108,6 +114,8 @@ if $extern_usb_disk || $extern_sata_disk ; then
fi
fi
elif $remote_disk ; then
backup_resource="$(grep "$backup_mountpoint" /etc/fstab | grep -v -E "\s*#" | awk '{print$1}' | head -1)"
elif $intern_disk ; then
if $crypto_backup_device ; then
backup_raw_partition=$_backup_partition
@ -182,7 +190,7 @@ _DEBUG=0
#
_TEST=0
export LOCK_DIR admin_email from_address content_type company hosts_base_dir intern_disk extern_usb_disk extern_sata_disk crypto_backup_device backup_base_dir backup_partition check_mountpoint info_file logFile logDuration right_tabstop disk_label_log_file force_level_1 MIRROR ARCHIVE days _DEBUG _TEST
export LOCK_DIR admin_email from_address content_type company hosts_base_dir intern_disk extern_usb_disk extern_sata_disk crypto_backup_device backup_base_dir backup_partition backup_resource check_mountpoint info_file logFile logDuration right_tabstop disk_label_log_file force_level_1 MIRROR ARCHIVE days _DEBUG _TEST
#
# ------------------ Ende Variable ------------------ #

127
rcopy.sh
View File

@ -40,6 +40,16 @@ logrotate_conf_file="$rcopy_base_dir/conf/logrotate.conf"
[ -f $rcopy_conf_file ] || exit 1
. $rcopy_conf_file
# - Be compartible with older configuration files
# -
if [ "X$remote_disk" = "X" ] ; then
remote_disk=false
fi
if [ "X$check_mountpoint" = "X" ] ; then
check_mountpoint=false
fi
[ -f $rcopy_functions_file ] || exit 1
. $rcopy_functions_file
@ -69,11 +79,6 @@ else
fi
if [ "X$check_mountpoint" = "X" ] ; then
check_mountpoint=false
fi
if $check_mountpoint ; then
if [[ ! -d $backup_mountpoint ]];then
msg00="[ Error ]: Mountpoint \"$backup_mountpoint\" for Backup Partion \"$backup_partition\" not found.\n"
@ -110,20 +115,54 @@ if $extern_usb_disk || $extern_sata_disk || $intern_disk ; then
fi
exit 1
fi
elif $check_mountpoint ; then
elif $remote_disk ; then
if ! df | grep "$backup_mountpoint" > /dev/null 2>&1 ;then
msg00="[ Error ]: Mountpoint \"$backup_mountpoint\" for Backup Partion \"$backup_partition\" not found.\n"
msg01=" exiting now.."
msg="${msg00}\n${msg01}"
mount "$backup_mountpoint" > /dev/null 2>&1
fi
sleep 2
if ! df | grep "$backup_mountpoint" > /dev/null 2>&1 ;then
msg="[ Error ]: Mounting remote disk to '$backup_mountpoint' failed. exiting now.."
if $manual ; then
echo -e "\n$msg\n"
else
datum=`date +"%d.%m.%Y"`
echo -e "To:${admin_email}\nSubject:Backup Errors $company -- $datum\n${msg}\n" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $admin_email
echo -e "To:${admin_email}\n${content_type}\nSubject:Backup Errors $company -- $datum\n${msg}\n" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $admin_email
fi
exit 1
fi
#elif $check_mountpoint ; then
# if ! df | grep "$backup_mountpoint" > /dev/null 2>&1 ;then
# msg00="[ Error ]: Mountpoint \"$backup_mountpoint\" for Backup Partion \"$backup_partition\" not found.\n"
# msg01=" exiting now.."
# msg="${msg00}\n${msg01}"
# if $manual ; then
# echo -e "\n$msg\n"
# else
# datum=`date +"%d.%m.%Y"`
# echo -e "To:${admin_email}\nSubject:Backup Errors $company -- $datum\n${msg}\n" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $admin_email
# fi
# exit 1
# fi
fi
if $extern_usb_disk || $extern_sata_disk || $intern_disk || $remote_disk ; then
sleep 2
if ! df | grep "$backup_partition" > /dev/null 2>&1 ;then
msg="[ Error ]: Cannot mount Backup Partion \"$backup_partition\". exiting now.."
if $manual ; then
echo -e "\n$msg\n"
else
datum=`date +"%d.%m.%Y"`
echo -e "To:${admin_email}\n${content_type}\nSubject:Backup Errors $company -- $datum\n${msg}\n" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $admin_email
fi
exit 1
fi
fi
## - $AGENT muss (root) gehören und darf nicht beschreibbar sein
@ -198,6 +237,7 @@ fi
## -
if $manual ; then
host_scripts="${hosts_base_dir}/localhost.sh"
host_scripts="${hosts_base_dir}/gw-km.anw-km.netz.sh"
else
host_scripts=`$find $hosts_base_dir -maxdepth 1 -type f -perm -700 | $sort`
fi
@ -253,38 +293,43 @@ if $found ; then
root_s="0$root_s"
fi
## - write backup info to
## -
if $extern_usb_disk || $extern_sata_disk ; then
## - write backup info to
## -
label=`tune2fs -l $backup_partition | grep -e "Filesystem volume name:" | awk '{print$4}'`
echo >> $info_file
echo -e "\tBackup Host.........: $BACKUP_HOST" >> $info_file
echo -e "\tBackup Date.........: `/bin/date +'%d.%m.%Y'`" >> $info_file
echo -e "\tBackup Time.........: `/bin/date +'%H:%M'` h" >> $info_file
echo >> $info_file
echo -e "\tbackup_disk_label...: $label" >> $info_file
echo >> $info_file
#echo -e "\tBackup Size.........: `du -sm $backup_base_dir | awk '{print$1}' ` MB" >> $info_file
echo >> $info_file
## - save current backup_disk_label
## -
echo "$label" > $disk_label_log_file
if cp $info_file $backup_base_dir > /dev/null ; then
echolog "write backup info to $backup_base_dir/`basename $info_file` .. [ ok ] \n"
else
echolog "[Error]: write backup info to $backup_base_dir/`basename $info_file` ..[ failed ]\n"
fi
rm -f $info_file
label="$(tune2fs -l $backup_partition | grep -e "Filesystem volume name:" | awk '{print$4}')"
elif $remote_disk ; then
label="$backup_resource"
elif $intern_disk ; then
label="$backup_partition"
else
label="$backup_base_dir"
fi
echo >> $info_file
echo -e "\tBackup Host...............: $BACKUP_HOST" >> $info_file
echo -e "\tBackup Date...............: `/bin/date +'%d.%m.%Y'`" >> $info_file
echo -e "\tBackup Time...............: `/bin/date +'%H:%M'` h" >> $info_file
echo >> $info_file
echo -e "\tBackup resource / Label...: $label" >> $info_file
echo >> $info_file
#echo -e "\tBackup Size.........: `du -sm $backup_base_dir | awk '{print$1}' ` MB" >> $info_file
echo >> $info_file
## - save current backup_disk_label
## -
echo "$label" > $disk_label_log_file
if cp $info_file $backup_base_dir > /dev/null ; then
echolog "write backup info to $backup_base_dir/`basename $info_file` .. [ ok ] \n"
else
echolog "[Error]: write backup info to $backup_base_dir/`basename $info_file` ..[ failed ]\n"
fi
rm -f $info_file
echolog "\nend backup \"$company\" : $root_backup_date ( ${root_end_h}:${root_end_m} h ) - duration: ${root_h} h : ${root_m} min : ${root_s} sec\n\n"
@ -351,8 +396,8 @@ if $extern_usb_disk || $extern_sata_disk ; then
fi
fi
fi
else
$umount $backup_partition 2> /dev/null
elif $remote_disk || $intern_disk ; then
$umount $backup_mountpoint 2> /dev/null
fi