diff --git a/.gitignore b/.gitignore index e281df1..64a5c72 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.swp +/conf/exclude_from.list /conf/logrotate.conf /conf/rcopy.conf /conf/manual_hosts.conf diff --git a/conf/rcopy.conf.00 b/conf/rcopy.conf.00 new file mode 100644 index 0000000..f63ed98 --- /dev/null +++ b/conf/rcopy.conf.00 @@ -0,0 +1,280 @@ +####################################################### +## 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="argus@oopen.de" +#from_address="backup@`hostname -f`" +from_address="backup-ebs@oopen.de" +company="EBS" +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 + +rsync_exclude_file=${crontab_base_dir}/conf/exclude_from.list + + +extern_usb_disk=true +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=false + +## - if backup partion cannot be determined, try this one.. +## - +_backup_partition="/dev/sdg1" +backup_mountpoint="/mnt/backup" + +## - Should check, if backup partion is mounted ? usefull if +## - backup partion is not automounted after restart. +## - +check_mountpoint=false + +base_label_name="Backup-EBS" + + +## - if encrypted backup partition +## - +crypto_backup_device=true +crypto_key_file="/data/.keys/backup.key" +backup_partition_name=backup +#mount_flags="-o user_xattr,acl,barrier=1" +mount_flags="" + + +backup_partition= +disk_identifier= +_found=false + +if $crypto_backup_device ; then + + backup_raw_partition=$_backup_partition + backup_partition="/dev/mapper/${backup_partition_name}" + +elif $extern_usb_disk || $extern_sata_disk || $intern_disk ; then + + ## - 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 -i $base_label_name`) + [[ "X${backup_partition}" != "X$(realpath /dev/disk/by-label/)" ]] && _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_partition=$_backup_partition + + else + backup_partition=/dev/$disk_identifier + fi + + fi + +elif $remote_disk ; then + + backup_resource="$(grep "$backup_mountpoint" /etc/fstab | grep -v -E "\s*#" | awk '{print$1}' | head -1)" + +fi + +## - send reminder for changing the backup disk +## - +#send_reminder=true +send_reminder=true +reminder_day="Montag" ## - maybe you have set to "Monday" +reminder_email="kontakt@kanzlei-ebs.de" +reminder_email_2="" + +backup_base_dir=${backup_mountpoint}/backup +#backup_base_dir=/backup + +## - 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 + + +## - Give global rsync arguments here. Maybe you wish +## - to exclude some files or diredtories +## - +## - Exclude from transfering +## - +## - **/dev/*random +## - *.log +## - *.log.[0-9] +## - *.log.[0-9],gz +## - *.log.[0-9][0-9].gz +## - **/sessions/* +## - **/*.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]* +## - +rsync_progArgs=" + --exclude **/dev/*random + --exclude *.log + --exclude *.log.[0-9] + --exclude *.log.[0-9].gz + --exclude *.log.[0-9][0-9].gz + --exclude **/sessions/* + --exclude 'System Volume Information' + --delete-excluded +" + +#if [ ! -s "${rsync_exclude_file}" ]; then +# rsync_progArgs="${rsync_progArgs} --exclude-from=${rsync_exclude_file}" +#fi +#rsyncExclude=("/System Volume Information/") + +## - Note: +## - If backup device is on remote host, then rsync needs arguments: +## - +if $remote_disk ; then + rsync_progArgs="--omit-link-times --munge-links $rsync_progArgs" +fi + + +## - 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 remote_disk crypto_backup_device backup_base_dir backup_partition backup_resource check_mountpoint info_file logFile logDuration right_tabstop disk_label_log_file rsync_progArgs 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` +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` + +ssh_opts='-o ControlMaster=auto -o ControlPath=/root/.ssh/%r@%h:%p -o ControlPersist=60' +if [[ -n "$ssh" ]] ; then + ssh="$ssh -n $ssh_opts" +fi + +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 ----------------- # +# --------------------------------------------------- # diff --git a/hosts/scripts/main_part.include b/hosts/scripts/main_part.include index 9db7d51..88ffebc 100644 --- a/hosts/scripts/main_part.include +++ b/hosts/scripts/main_part.include @@ -127,7 +127,7 @@ fi ## - [[ -z "$nextcloud_backup" ]] && nextcloud_backup=false -if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" -o "$disksetting_backup" = "true" -o "$nextcloud_backup" = "true" ] ; then +if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" -o "$disksetting_backup" = "true" -o "$nextcloud_backup" = "true" -o "$mount_netdir" = "true" ] ; then begin_h=`date +%H` begin_m=`date +%M` @@ -348,7 +348,7 @@ if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" if $mount_netdir; then echolog "\nGoing to backup network directories.. ( `$date +%H`:`$date +%M` h )" for dir in $net_mounted_dir_backup ; do - echolog "\n\tBackup network directory $dir" + #echolog "\n\tBackup network directory $dir" export mount_netdir backup_dir=$dir $script_dir/net_mounted_dir_backup.sh done diff --git a/rcopy_manual.sh b/rcopy_manual.sh index 6e1ba73..9e7de69 100755 --- a/rcopy_manual.sh +++ b/rcopy_manual.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash script_dir=$(realpath `dirname $0`) -$script_dir/rcopy.sh -m $* +$script_dir/rcopy.sh -m -B $* exit $?