Add Options 'ONLY_BACKUP' (do not handle existing archives) and 'NO_NEW_BACKUP' (do not backup any host, only handle existing archives).
This commit is contained in:
111
rcopy.sh
111
rcopy.sh
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
manual=$1
|
||||
NO_NEW_BACKUP=${NO_NEW_BACKUP:=false}
|
||||
manual=${manual:=false}
|
||||
|
||||
if [[ $manual != false && $manual != true ]]; then
|
||||
echo -e "\n[ Error ]: Usage: `basename $0` [true|false]\n"
|
||||
exit 2
|
||||
fi
|
||||
#if [[ $MANUAL != false && $MANUAL != true ]]; then
|
||||
# echo -e "\n[ Error ]: Usage: `basename $0` [true|false]\n"
|
||||
# exit 2
|
||||
#fi
|
||||
|
||||
## - if you plan to run the backup scripts as a cronjob,
|
||||
## - you have to set this variable manually
|
||||
@@ -18,29 +18,52 @@ USER=$LOGNAME
|
||||
rcopy_base_dir="$(realpath $(dirname $0))"
|
||||
rcopy_conf_file="$rcopy_base_dir/conf/rcopy.conf"
|
||||
rcopy_functions_file=$rcopy_base_dir/conf/rcopy_functions.conf
|
||||
## - location of the logfile
|
||||
## -
|
||||
logFile="/var/log/rcopy.log"
|
||||
disk_label_log_file="/var/log/backup_disk-label.log"
|
||||
|
||||
export rcopy_base_dir rcopy_conf_file rcopy_functions_file
|
||||
|
||||
if $manual ; then
|
||||
## - this is for manual start, we don't want inform anyone and
|
||||
## - also don't restart any service
|
||||
## -
|
||||
send_reminder=false
|
||||
restart_samba_service=false
|
||||
manual_hosts_file="${rcopy_base_dir}/conf/manual_hosts.conf"
|
||||
fi
|
||||
|
||||
## - Note: the file "/var/lib/logrotate/status" must have
|
||||
## - write permissions for the script-user
|
||||
## -
|
||||
logrotate_conf_file="$rcopy_base_dir/conf/logrotate.conf"
|
||||
if [[ -f "$rcopy_base_dir/conf/logrotate.conf" ]]; then
|
||||
logrotate_conf_file="$rcopy_base_dir/conf/logrotate.conf"
|
||||
elif [[ -f "$rcopy_base_dir/conf/logrotate.conf.sample" ]]; then
|
||||
logrotate_conf_file="$rcopy_base_dir/conf/logrotate.conf.sample"
|
||||
else
|
||||
logrotate_conf_file=""
|
||||
fi
|
||||
|
||||
[ -f $rcopy_functions_file ] || exit 1
|
||||
. $rcopy_functions_file
|
||||
|
||||
## - load configuration
|
||||
## -
|
||||
[ -f $rcopy_conf_file ] || exit 1
|
||||
. $rcopy_conf_file
|
||||
|
||||
NO_NEW_BACKUP=false
|
||||
ONLY_BACKUP=false
|
||||
MANUAL=false
|
||||
while getopts BhNm opt ; do
|
||||
case $opt in
|
||||
B) ONLY_BACKUP=true
|
||||
;;
|
||||
m) MANUAL=true
|
||||
;;
|
||||
N) NO_NEW_BACKUP=true
|
||||
;;
|
||||
h) usage
|
||||
;;
|
||||
\?) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if $ONLY_BACKUP && $NO_NEW_BACKUP ; then
|
||||
fatal "Parameter '-B' AND '-N' is not possible."
|
||||
fi
|
||||
|
||||
# - Be compartible with older configuration files
|
||||
# -
|
||||
if [ "X$remote_disk" = "X" ] ; then
|
||||
@@ -51,8 +74,35 @@ if [ "X$check_mountpoint" = "X" ] ; then
|
||||
check_mountpoint=false
|
||||
fi
|
||||
|
||||
[ -f $rcopy_functions_file ] || exit 1
|
||||
. $rcopy_functions_file
|
||||
|
||||
# ----------
|
||||
# - Read commandline parameter
|
||||
# ----------
|
||||
|
||||
if $MANUAL ; then
|
||||
## - this is for manual start, we don't want inform anyone and
|
||||
## - also don't restart any service
|
||||
## -
|
||||
send_reminder=false
|
||||
restart_samba_service=false
|
||||
manual_hosts_file="${rcopy_base_dir}/conf/manual_hosts.conf"
|
||||
fi
|
||||
|
||||
if $NO_NEW_BACKUP ; then
|
||||
## - Note: the file "/var/lib/logrotate/status" must have
|
||||
## - write permissions for the script-user
|
||||
## -
|
||||
if [[ -f "$rcopy_base_dir/conf/logrotate_handle-backups.conf" ]]; then
|
||||
logrotate_conf_file="$rcopy_base_dir/conf/logrotate_handle-backups.conf"
|
||||
elif [[ -f "$rcopy_base_dir/conf/logrotate_handle-backups.conf.sample" ]]; then
|
||||
logrotate_conf_file="$rcopy_base_dir/conf/logrotate_handle-backups.conf.sample"
|
||||
else
|
||||
logrotate_conf_file=""
|
||||
fi
|
||||
logFile="/var/log/rcopy-handle_backups.log"
|
||||
fi
|
||||
|
||||
export logFile disk_label_log_file ONLY_BACKUP NO_NEW_BACKUP rcopy_base_dir rcopy_conf_file rcopy_functions_file
|
||||
|
||||
## - if backup job already runs, stop execution..
|
||||
## -
|
||||
@@ -64,7 +114,7 @@ if mkdir "$LOCK_DIR" 2> /dev/null ; then
|
||||
else
|
||||
|
||||
msg="[ Error ]: A previos instance of the backup script seems already be running.\n\tExiting now.."
|
||||
if $manual ; then
|
||||
if $MANUAL ; then
|
||||
echo -e "\n$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -80,12 +130,17 @@ else
|
||||
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "MANUAL: $MANUAL"
|
||||
echo "NO_NEW_BACKUP: $NO_NEW_BACKUP"
|
||||
|
||||
|
||||
if $check_mountpoint ; then
|
||||
if [[ ! -d $backup_mountpoint ]];then
|
||||
msg00="[ Error ]: Mountpoint \"$backup_mountpoint\" for Backup Partion \"$backup_partition\" not found.\n"
|
||||
msg01=" exiting now.."
|
||||
msg="${msg00}\n${msg01}"
|
||||
if $manual ; then
|
||||
if $MANUAL ; then
|
||||
echo -e "\n$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -108,7 +163,7 @@ if $extern_usb_disk || $extern_sata_disk || $intern_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
|
||||
if $MANUAL ; then
|
||||
echo -e "\n$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -126,7 +181,7 @@ elif $remote_disk ; then
|
||||
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
|
||||
if $MANUAL ; then
|
||||
echo -e "\n$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -140,7 +195,7 @@ elif $remote_disk ; then
|
||||
# msg00="[ Error ]: Mountpoint \"$backup_mountpoint\" for Backup Partion \"$backup_partition\" not found.\n"
|
||||
# msg01=" exiting now.."
|
||||
# msg="${msg00}\n${msg01}"
|
||||
# if $manual ; then
|
||||
# if $MANUAL ; then
|
||||
# echo -e "\n$msg\n"
|
||||
# else
|
||||
# datum=`date +"%d.%m.%Y"`
|
||||
@@ -154,7 +209,7 @@ 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
|
||||
if $MANUAL ; then
|
||||
echo -e "\n$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -183,7 +238,7 @@ if [ ! -O $AGENT ]; then
|
||||
msg_02="\t !! BACKUP INTERUPTED !!"
|
||||
msg_03="As user \"$USER\" do:\n\tssh-agent > $AGENT; . $AGENT; ssh-add"
|
||||
msg="${msg_00}\n\n${msg_01}\n${msg_02}\n${msg_01}\n\n${msg_03}"
|
||||
if $manual ; then
|
||||
if $MANUAL ; then
|
||||
echo -e "\n$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -202,7 +257,7 @@ if [ ! `$ps aux | $grep -e"^$USER" | $grep "$SSH_AGENT_PID" | $grep ssh-agent |
|
||||
msg_02="\t !! BACKUP INTERUPTED !!"
|
||||
msg_03="As user \"$USER\" do:\n\tssh-agent > $AGENT; . $AGENT; ssh-add"
|
||||
msg="${msg_00}\n\n${msg_01}\n${msg_02}\n${msg_01}\n\n${msg_03}"
|
||||
if $manual ; then
|
||||
if $MANUAL ; then
|
||||
echo -e "$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -222,7 +277,7 @@ if [ ! $? -eq 0 ]; then
|
||||
msg_02="\t !! BACKUP INTERUPTED !!"
|
||||
msg_03="As user \"$USER\" do:\n\tssh-agent > $AGENT; . $AGENT; ssh-add"
|
||||
msg="${msg_00}\n\n${msg_01}\n${msg_02}\n${msg_01}\n\n${msg_03}"
|
||||
if $manual ; then
|
||||
if $MANUAL ; then
|
||||
echo -e "\n$msg\n"
|
||||
else
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
@@ -237,7 +292,7 @@ fi
|
||||
## - searching hosts for backup
|
||||
## -
|
||||
host_scripts=""
|
||||
if $manual ; then
|
||||
if $MANUAL ; then
|
||||
if [[ -f "$manual_hosts_file" ]] ; then
|
||||
source "$manual_hosts_file"
|
||||
for script in $hosts ; do
|
||||
|
||||
Reference in New Issue
Block a user