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