SicherPC.sh changed to be more generic

This commit is contained in:
Ulf 2021-11-01 22:49:18 +01:00
parent fcae9d38f1
commit 17410278dc

View file

@ -1,63 +1,62 @@
#!/bin/sh #!/bin/sh
# Sichere wichtige Einstellungen # Save some data on a mounted filesystem
# #
# Ulf@ulf-bartholomaeus.de # (c) LUG-VS (GPL)
VERSION="Version 0.2.3 from 28.09.2021" VERSION="$(basename $0) Version 1.0.0 from 2021-11-01"
# 0.2.3 ##
# update pathes # Requires root rights!
# 0.2.2 # Input: -v for verbose
# fixed test -f /proc/mdstat -> removed "cat" and remove ";" after "do" # Output: saved data
# 0.2.1
# lspcci Umleitung in Datei gefixt
# 0.2.0
# verschiedene HW info hinzu (ab "HW-Info")
# 0.1.9
# home.luna -> home.maxi
# 0.1.8
# /var/lib/named ebenfalls sichern
# 0.1.7
# Fehler /bin/etc -> /usr/etc
# 0.1.6
# Backup um /var/yp/ und /usr/lib/ypbind/ ergänzen
# 0.1.5:
# /mnt/data2/PC-Sicherungen => /home.luna/users/PC-Sicherungen aktualisiert
# Check /mnt/backup and /mnt/bkp
# 0.1.4:
# /bin/etc hinzu
if [ -d /home.maxi/users/PC-Sicherungen ] ; then ##
MyDest=/home.maxi/users/PC-Sicherungen # 1.0.0
else # branch for sharing
if [ -d /home/users/PC-Sicherungen ] ; then
MyDest=/home/users/PC-Sicherungen ## Define destination (e.g. NFS or DavFS mounted remote NAS or trusted Server)
else MyDest="/mnt/remote"
## Check if Destination exists
if [ ! -d ${MyDest} ] ; then
echo "*** Error: No Destination found" echo "*** Error: No Destination found"
exit 10 exit 10
fi
fi fi
## Generate dedicated subdirectory for each host PC
if [ -d ${MyDest}/$(hostname) ] ; then if [ -d ${MyDest}/$(hostname) ] ; then
MyDest=${MyDest}/$(hostname) MyDest=${MyDest}/$(hostname)
fi fi
## Short message (in this case in German) showing the what was done
if [ "$1"="-v" ] ; then if [ "$1"="-v" ] ; then
echo "Sichere /etc und /root sowie SmartCtl in Ziel <${MyDest}>" echo "Sichere /etc und /root sowie SmartCtl in Ziel <${MyDest}>"
fi fi
#tgz ${MyDest}/$(hostname)_$(date +%F)_etc.tgz /etc /usr/etc
## Save main settings and personal data of root
tar -cvzf ${MyDest}/$(hostname)_$(date +%F)_etc.tgz /etc /usr/etc tar -cvzf ${MyDest}/$(hostname)_$(date +%F)_etc.tgz /etc /usr/etc
#tgz ${MyDest}/$(hostname)_$(date +%F)_root.tgz /root
tar -cvz --exclude=/root/.duc.db -f ${MyDest}//$(hostname)_$(date +%F)_root.tgz /root tar -cvz --exclude=/root/.duc.db -f ${MyDest}//$(hostname)_$(date +%F)_root.tgz /root
[ -d /var/lib/named/ ] && tgz ${MyDest}/$(hostname)_$(date +%F)_named.tgz /var/lib/named/ [ -d /var/lib/named/ ] && tgz ${MyDest}/$(hostname)_$(date +%F)_named.tgz /var/lib/named/
[ -d /var/yp/ ] && tgz ${MyDest}/$(hostname)_$(date +%F)_yp.tgz /var/yp/ [ -d /var/yp/ ] && tgz ${MyDest}/$(hostname)_$(date +%F)_yp.tgz /var/yp/
[ -d /usr/lib/ypbind/ ] && tgz ${MyDest}/$(hostname)_$(date +%F)_ypbind.tgz /usr/lib/ypbind/ [ -d /usr/lib/ypbind/ ] && tgz ${MyDest}/$(hostname)_$(date +%F)_ypbind.tgz /usr/lib/ypbind/
## HW-Info
which hwinfo &> /dev/null && hwinfo &> ${MyDest}/hwinfo_$(date +%F).txt ## Some other informations like HW interfaces and disks
which hwinfo &> /dev/null && hwinfo --short &> ${MyDest}/hwinfo-short_$(date +%F).txt which lsusb &> /dev/null && lsusb &> ${MyDest}/lsusb_$(date +%F).txt
which inxi &> /dev/null && inxi -Fxd &>> ${MyDest}/inxi-Fxd_$(date +%F).txt ## disabled da inxi sich in scripten aufhängt which lspci &> /dev/null && lspci &> ${MyDest}/lspcci_$(date +%F).txt
which lspci &> /dev/null && lspci &> ${MyDest}/lspcci _$(date +%F).txt
which fdisk &> /dev/null && fdisk -l &>> ${MyDest}/fdisk-l_$(date +%F).txt which fdisk &> /dev/null && fdisk -l &>> ${MyDest}/fdisk-l_$(date +%F).txt
which lsblk &> /dev/null && lsblk &>> ${MyDest}/lsblk_$(date +%F).txt which lsblk &> /dev/null && lsblk &>> ${MyDest}/lsblk_$(date +%F).txt
cp /etc/fstab ${MyDest}/fstab_$(date +%F).txt
which mdadm &> /dev/null && for dev in $( mdadm -Ebsc=partitions | cut -d' ' -f2 ) ; do mdadm -D $dev &>> ${MyDest}/mdadm-D_$(date +%F).txt ; done ## If sensors then save sensor informations like temperature and voltages
[ -f /proc/mdstat ] && cp /proc/mdstat ${MyDest}/mdstat_$(date +%F).txt
which sensors &> /dev/null && sensors &> ${MyDest}/sensors_$(date +%F).txt which sensors &> /dev/null && sensors &> ${MyDest}/sensors_$(date +%F).txt
which sensors &> /dev/null && sensors -u &>> ${MyDest}/sensors-u_$(date +%F).txt which sensors &> /dev/null && sensors -u &>> ${MyDest}/sensors-u_$(date +%F).txt
## If inxi is installed then save this info
which inxi &> /dev/null && inxi -Fxd &>> ${MyDest}/inxi-Fxd_$(date +%F).txt ## disabled da inxi sich in scripten aufhängt
## If mdadm is installed and /proc/mdstat exists than save raid infos
which mdadm &> /dev/null && for dev in $( mdadm -Ebsc=partitions | cut -d' ' -f2 ) ; do mdadm -D $dev &>> ${MyDest}/mdadm-D_$(date +%F).txt ; done
[ -f /proc/mdstat ] && cp /proc/mdstat ${MyDest}/mdstat_$(date +%F).txt
## Store some HW-Info
# if hwinfo (e.g. at openSUSE) existis
which hwinfo &> /dev/null && hwinfo &> ${MyDest}/hwinfo_$(date +%F).txt
which hwinfo &> /dev/null && hwinfo --short &> ${MyDest}/hwinfo-short_$(date +%F).txt