Initial import - (formaly a SVN project named rcopy)
This commit is contained in:
62
conf/logrotate.conf.sample
Normal file
62
conf/logrotate.conf.sample
Normal file
@ -0,0 +1,62 @@
|
||||
# I put everything in one block and added sharedscripts, so that mysql gets
|
||||
# flush-logs'd only once.
|
||||
# Else the binary logs would automatically increase by n times every day.
|
||||
/var/log/rsync.log {
|
||||
daily
|
||||
rotate 7
|
||||
missingok
|
||||
compress
|
||||
su root root
|
||||
prerotate
|
||||
|
||||
filesystem=`df`
|
||||
|
||||
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"'
|
||||
|
||||
extra_error_email=""
|
||||
|
||||
## - These variables will be exportet from backup script (rcopy.sh)
|
||||
## -
|
||||
## - admin_email from_address company logFile logDuration
|
||||
#admin_email="argus@oopen.de"
|
||||
#from_address="root@`hostname -f`"
|
||||
#company="Warenform INET"
|
||||
#logFile=/backup/log/rsync.log
|
||||
|
||||
durations_top="\nBackup durations of the certain hosts:\n"
|
||||
durations="${durations_top}`cat $logDuration`\n"
|
||||
|
||||
send=`cat $logFile`
|
||||
|
||||
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
|
||||
|
||||
declare -i error=`grep -e"\[ERROR" $logFile | wc -l`
|
||||
declare -i warning=`grep -e"\[WARN" $logFile | wc -l`
|
||||
|
||||
if [ $error -gt 0 -o $warning -gt 0 ] ; then
|
||||
|
||||
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_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}"
|
||||
|
||||
msg="${msg_top}\n${msg_body_01}\n${msg_body_02}"
|
||||
|
||||
echo -e "To:${admin_email}\n${content_type}\nSubject:Backup Errors $company -- $datum\n${msg}" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $admin_email
|
||||
if [ "X$extra_error_email" != "X" ]; then
|
||||
echo -e "To:${extra_error_email}\n${content_type}\nSubject:Backup Errors $company -- $datum\n${msg}" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $extra_error_email
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
endscript
|
||||
}
|
236
conf/rcopy.conf.sample
Normal file
236
conf/rcopy.conf.sample
Normal file
@ -0,0 +1,236 @@
|
||||
#######################################################
|
||||
## Configuration-file for remote backupscript ##
|
||||
#######################################################
|
||||
|
||||
# --------------------------------------------------- #
|
||||
# -------------------- Variable --------------------- #
|
||||
#
|
||||
|
||||
## - Lock directory exists, until the script ends. So
|
||||
## - we can check, if a previos instanze is already running.
|
||||
## -
|
||||
## - That directory is also userd for temporary files
|
||||
## -
|
||||
LOCK_DIR=/tmp/rcopy.lock
|
||||
|
||||
## --------------------------------------
|
||||
## - variables only used in parent script
|
||||
## -
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
BACKUP_HOST=`hostname -f`
|
||||
|
||||
HOME_DIR=$HOME
|
||||
AGENT=/tmp/.agent-$USER.sh
|
||||
|
||||
admin_email="<ADMIN_EMAIL>"
|
||||
from_address="backup@`hostname -f`"
|
||||
company="<COMPANY>"
|
||||
content_type='Content-Type: text/plain;\n charset="utf-8"'
|
||||
|
||||
restart_samba_service=false
|
||||
samba_exe=/usr/local/samba/sbin/samba
|
||||
samba_init_script=/etc/init.d/samba4
|
||||
|
||||
|
||||
## --------------------------------
|
||||
## - variables, used in subshells..
|
||||
## -
|
||||
|
||||
#REMOTE_USER=back
|
||||
|
||||
crontab_base_dir=$rcopy_base_dir
|
||||
hosts_base_dir=$crontab_base_dir/hosts
|
||||
|
||||
|
||||
extern_usb_disk=false
|
||||
extern_sata_disk=false
|
||||
intern_disk=false
|
||||
|
||||
## - if backup partion cannot be determined, try this one..
|
||||
## -
|
||||
_backup_partition="<BACKUP_PARTITION>"
|
||||
backup_mountpoint="<BACKUP_MOUNTPOINT>"
|
||||
|
||||
## - Should check, if backup partion is mounted ? usefull if
|
||||
## - backup partion is not automounted after restart.
|
||||
## -
|
||||
check_mountpoint=false
|
||||
|
||||
base_label_name="<BACKUP-AH>"
|
||||
|
||||
|
||||
## - if encrypted backup partition
|
||||
## -
|
||||
crypto_backup_device=false
|
||||
crypto_key_file="<CRYPTO_KEY_FILE>"
|
||||
backup_partition_name=backup
|
||||
#mount_flags="-o user_xattr,acl,barrier=1"
|
||||
mount_flags=""
|
||||
|
||||
if $extern_usb_disk || $extern_sata_disk ; then
|
||||
|
||||
backup_partition=
|
||||
backup_raw_partition=
|
||||
disk_identifier=
|
||||
_found=false
|
||||
|
||||
## - In case of unencrypted (and labeled) extern backup disc
|
||||
## -
|
||||
if [ -d "/dev/disk/by-label" ]; then
|
||||
backup_partition=$(realpath /dev/disk/by-label/`ls /dev/disk/by-label | grep $base_label_name`)
|
||||
[[ "X" != "X$backup_raw_partition" ]] && _found=true
|
||||
fi
|
||||
|
||||
## - Otherwise, assuming the backup disc is the alphabetic last attached device
|
||||
## - in device list
|
||||
## -
|
||||
if ! $_found ; then
|
||||
for file in `ls /dev/disk/by-uuid` ; do
|
||||
_disk=`basename $(realpath /dev/disk/by-uuid/$file) | grep -e "^sd"`
|
||||
[[ "X" = "${_disk}X" ]] && continue
|
||||
[[ "$disk_identifier" < "$_disk" ]] && disk_identifier=$_disk
|
||||
done
|
||||
|
||||
if [ "X$disk_identifier" = "X" ]; then
|
||||
## - Backup device could not be detected, so we will try the (above) given one..
|
||||
## -
|
||||
backup_raw_partition=$_backup_partition
|
||||
else
|
||||
backup_raw_partition=/dev/$disk_identifier
|
||||
fi
|
||||
|
||||
if $crypto_backup_device ; then
|
||||
backup_partition="/dev/mapper/${backup_partition_name}"
|
||||
else
|
||||
backup_partition=$backup_raw_partition
|
||||
fi
|
||||
|
||||
fi
|
||||
elif $intern_disk ; then
|
||||
if $crypto_backup_device ; then
|
||||
backup_raw_partition=$_backup_partition
|
||||
backup_partition="/dev/mapper/${backup_partition_name}"
|
||||
else
|
||||
backup_partition=$_backup_partition
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
## - send reminder for changing the backup disk
|
||||
## -
|
||||
#send_reminder=true
|
||||
send_reminder=false
|
||||
reminder_day="Montag" ## - maybe you have set to "Monday"
|
||||
reminder_email="<REMINDER_EMAIL>"
|
||||
reminder_email_2=""
|
||||
|
||||
backup_base_dir=${backup_mountpoint}/backup
|
||||
#backup_base_dir=/backup
|
||||
|
||||
## - location of the logfile
|
||||
## -
|
||||
logFile="/var/log/rsync.log"
|
||||
disk_label_log_file="/var/log/backup_disk-label.log"
|
||||
|
||||
## - logging backup durations in an different file
|
||||
## - NOTICE:
|
||||
## - because of the process number in the filename, take care, not to
|
||||
## - override it by child processes, which also read this file
|
||||
## -
|
||||
## - for a better looking, define a right hand tab stop
|
||||
## -
|
||||
if [ -z "$logDuration" ];then
|
||||
logDuration=${LOCK_DIR}/duration.log
|
||||
fi
|
||||
right_tabstop=60
|
||||
|
||||
|
||||
info_file="/tmp/LAST_BACKUP_archiv.info"
|
||||
> $info_file
|
||||
|
||||
|
||||
## - force to create level 1 backups. the backups are not cascaded, they
|
||||
## - all are direct related to the complete one.
|
||||
## -
|
||||
force_level_1=true
|
||||
|
||||
|
||||
## - What to do
|
||||
## - Note: 1) without mirroring no archiving will be done
|
||||
## - 2) in case of database backup only the parameter
|
||||
## - "MIRROR" will be considered
|
||||
## -
|
||||
MIRROR=true
|
||||
ARCHIVE=true
|
||||
|
||||
## - how long to hold backup-files ?
|
||||
## -
|
||||
days=15
|
||||
|
||||
# a bigger (integer-)value for_DEBUG "1"results in more
|
||||
# infomation, written to the logFile
|
||||
#
|
||||
# possible values: 0 , 1 or 2
|
||||
#
|
||||
_DEBUG=0
|
||||
|
||||
# if _TEST is set to "1", nothing will be done. instead
|
||||
# rsync will just report the actions it would have
|
||||
# taken to the $logFile
|
||||
#
|
||||
_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
|
||||
|
||||
#
|
||||
# ------------------ Ende Variable ------------------ #
|
||||
# --------------------------------------------------- #
|
||||
|
||||
|
||||
|
||||
# --------------------------------------------------- #
|
||||
# -------------------- Programme -------------------- #
|
||||
#
|
||||
basename=`which basename`
|
||||
dirname=`which dirname`
|
||||
awk=`which awk`
|
||||
cat=`which cat`
|
||||
cryptsetup=`which cryptsetup`
|
||||
cut=`which cut`
|
||||
date=`which date`
|
||||
dd=`which dd`
|
||||
e2fsck=`which e2fsck`
|
||||
find=`which find`
|
||||
fdisk=`which fdisk`
|
||||
grep=`which grep`
|
||||
gzip=`which gzip`
|
||||
hdparm=`which hdparm`
|
||||
logrotate=`which logrotate`
|
||||
mkdir=`which mkdir`
|
||||
mount=`which mount`
|
||||
mv=`which mv`
|
||||
parted=`which parted`
|
||||
ps=`which ps`
|
||||
rm=`which rm`
|
||||
rsync=`which rsync`
|
||||
scp=`which scp`
|
||||
sgdisk=`which sgdisk`
|
||||
#ssh=`which ssh`
|
||||
ssh="`which ssh` -n"
|
||||
sort=`which sort`
|
||||
tar=`which tar`
|
||||
tune2fs=`which tune2fs`
|
||||
umount=`which umount`
|
||||
sfdisk=`which sfdisk`
|
||||
su=`which su`
|
||||
sudo=`which sudo`
|
||||
sort=`which sort`
|
||||
sync=`which sync`
|
||||
touch=`which touch`
|
||||
|
||||
export basename dirname awk cat cryptsetup cut date dd e2fsck find fdisk grep gzip hdparm logrotate mkdir mount mv parted ps rm rsync scp ssh sort tar tune2fs umount sfdisk sgdisk su sudo sort sync touch
|
||||
#
|
||||
# ------------------ Ende Programme ----------------- #
|
||||
# --------------------------------------------------- #
|
54
conf/rcopy_functions.conf
Normal file
54
conf/rcopy_functions.conf
Normal file
@ -0,0 +1,54 @@
|
||||
#######################################################
|
||||
## Functions for remote backupscript ##
|
||||
#######################################################
|
||||
|
||||
# --------------------------------------------------- #
|
||||
# ------------------- Funktionen -------------------- #
|
||||
#
|
||||
echolog(){
|
||||
if [ -n "$2" ];then
|
||||
case $_DEBUG in
|
||||
0)
|
||||
if [ "$2" -eq 0 ]; then
|
||||
echo -e "$1" >> $logFile
|
||||
fi
|
||||
;;
|
||||
1)
|
||||
if [ "$2" -lt 2 ]; then
|
||||
echo -e "$1" >> $logFile
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
echo -e "$1" >> $logFile
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo -e "$1" >> $logFile
|
||||
fi
|
||||
}
|
||||
#
|
||||
#
|
||||
echononl(){
|
||||
echo X\\c > /tmp/shprompt$$
|
||||
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
||||
# echo "$*\\c" 1>&2
|
||||
echo "$*\\c" >> $logFile
|
||||
else
|
||||
# echo -e -n "$*" 1>&2
|
||||
echo -e -n "$*" >> $logFile
|
||||
fi
|
||||
rm /tmp/shprompt$$
|
||||
}
|
||||
#
|
||||
#
|
||||
fatal(){
|
||||
echolog "!!! The backup procedure was interrupted !!!"
|
||||
echolog "\nError:\n\t $*"
|
||||
echolog "\n*** End Update -- no backups are done ***\n\n"
|
||||
exit 1
|
||||
}
|
||||
#
|
||||
# ------------------ Ende Funktionen ---------------- #
|
||||
# --------------------------------------------------- #
|
Reference in New Issue
Block a user