Obvious fail of array matching fix

This commit is contained in:
gospodar 2023-02-22 18:01:41 +01:00
parent 685b149045
commit 65b5b20b18

94
main.sh
View File

@ -62,7 +62,7 @@ function vhostbackup {
if [ "$vhost_backup" = true ]; then
echo "Backing up vhosts..." >&2
mkdir -p "$tmpdir/vhosts"
cp -r "$vhost_dir/" "$tmpdir/vhosts/"
cp -avr "$vhost_dir/" "$tmpdir/vhosts/"
echo "Finished" >&2
fi
}
@ -75,99 +75,99 @@ function logbackup {
case $system in
"rhel")
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[fail2ban]} " ]]; then
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[apache]} " ]]; then
mkdir -p "$tmpdir/apachelogs"
cp -r /var/log/httpd "$tmpdir/apachelogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[nginx]} " ]]; then
mkdir -p "$tmpdir/nginxlogs"
cp -r /var/log/nginx "$tmpdir/nginxlogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${alternatives} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[alternatives]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/alternatives.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${pckg_mngr} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[pckg_mngr]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
mkdir -p "$tmpdir/syslogs/yum"
cp -r /var/log/yum/* "$tmpdir/syslogs/yum/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${auth} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[auth]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/auth.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${dmesg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dmesg]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/dmesg "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${dpkg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dpkg]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/dpkg.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${letsencrypt} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[letsencrypt]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
mkdir -p "$tmpdir/syslogs/letsencrypt"
cp -r /var/log/letsencrypt/* "$tmpdir/syslogs/letsencrypt/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${php} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[php]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/php*.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${syslog} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[syslog]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/syslog "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[purge]} " ]]; then
echo "Purging logs..." >&2
truncate -s 0 /var/log/syslog
truncate -s 0 /var/log/message
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[apache]} " ]]; then
truncate -s 0 /var/log/httpd/*
rm /var/log/httpd/*.gz
fi
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[nginx]} " ]]; then
truncate -s 0 /var/log/nginx/*
rm /var/log/nginx/*.gz
fi
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[fail2ban]} " ]]; then
truncate -s 0 /var/log/fail2ban.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${alternatives} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[alternatives]} " ]]; then
truncate -s 0 /var/log/alternatives.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${pckg_mngr} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[pckg_mngr]} " ]]; then
truncate -s 0 /var/log/yum/*
fi
if [[ " ${log_to_backup[*]} " =~ " ${auth} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[auth]} " ]]; then
truncate -s 0 /var/log/auth.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${dmesg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dmesg]} " ]]; then
truncate -s 0 /var/log/dmesg
fi
if [[ " ${log_to_backup[*]} " =~ " ${dpkg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dpkg]} " ]]; then
truncate -s 0 /var/log/dpkg.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${letsencrypt} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[letsencrypt]} " ]]; then
truncate -s 0 /var/log/letsencrypt/*
fi
if [[ " ${log_to_backup[*]} " =~ " ${php} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[php]} " ]]; then
truncate -s 0 /var/log/php*.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${syslog} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[syslog]} " ]]; then
truncate -s 0 /var/log/syslog
fi
fi
@ -175,99 +175,99 @@ function logbackup {
"debian")
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[fail2ban]} " ]]; then
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[apache]} " ]]; then
mkdir -p "$tmpdir/apachelogs"
cp -r /var/log/apache2 "$tmpdir/apachelogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[nginx]} " ]]; then
mkdir -p "$tmpdir/nginxlogs"
cp -r /var/log/nginx "$tmpdir/nginxlogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${alternatives} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[alternatives]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/alternatives.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${pckg_mngr} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[pckg_mngr]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
mkdir -p "$tmpdir/syslogs/apt"
cp -r /var/log/apt/* "$tmpdir/syslogs/apt/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${auth} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[auth]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/auth.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${dmesg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dmesg]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/dmesg "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${dpkg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dpkg]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/dpkg.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${letsencrypt} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[letsencrypt]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
mkdir -p "$tmpdir/syslogs/letsencrypt"
cp -r /var/log/letsencrypt/* "$tmpdir/syslogs/letsencrypt/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${php} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[php]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/php*.log "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${syslog} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[syslog]} " ]]; then
mkdir -p "$tmpdir/syslogs/"
cp -r /var/log/syslog "$tmpdir/syslogs/"
fi
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[purge]} " ]]; then
echo "Purging logs..." >&2
truncate -s 0 /var/log/syslog
truncate -s 0 /var/log/message
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[apache]} " ]]; then
truncate -s 0 /var/log/apache2/*
rm /var/log/apache2/*.gz
fi
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[nginx]} " ]]; then
truncate -s 0 /var/log/nginx/*
rm /var/log/nginx/*.gz
fi
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[fail2ban]} " ]]; then
truncate -s 0 /var/log/fail2ban.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${alternatives} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[alternatives]} " ]]; then
truncate -s 0 /var/log/alternatives.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${pckg_mngr} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[pckg_mngr]} " ]]; then
truncate -s 0 /var/log/apt/*
fi
if [[ " ${log_to_backup[*]} " =~ " ${auth} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[auth]} " ]]; then
truncate -s 0 /var/log/auth.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${dmesg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dmesg]} " ]]; then
truncate -s 0 /var/log/dmesg
fi
if [[ " ${log_to_backup[*]} " =~ " ${dpkg} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[dpkg]} " ]]; then
truncate -s 0 /var/log/dpkg.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${letsencrypt} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[letsencrypt]} " ]]; then
truncate -s 0 /var/log/letsencrypt/*
fi
if [[ " ${log_to_backup[*]} " =~ " ${php} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[php]} " ]]; then
truncate -s 0 /var/log/php*.log
fi
if [[ " ${log_to_backup[*]} " =~ " ${syslog} " ]]; then
if [[ " ${log_to_backup[*]} " =~ " ${log_to_backup[syslog]} " ]]; then
truncate -s 0 /var/log/syslog
fi
fi