From b1683d9bccb72f49a2f4aa2e044481eff8f794c6 Mon Sep 17 00:00:00 2001 From: kneutron <50146127+kneutron@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:07:45 -0700 Subject: [PATCH] Add files via upload --- proxmox/BKPDEST.mrg | 32 ++++ proxmox/bkpcrit-proxmox.sh | 157 ++++++++++++++++++ proxmox/bkpsys-2fsarchive.sh | 118 +++++++++++++ proxmox/proxmox-enter-container.sh | 7 + proxmox/proxmox-refresh-ctr-templates.sh | 6 + .../proxmox-scan-samba-server-for-shares.sh | 4 + 6 files changed, 324 insertions(+) create mode 100644 proxmox/BKPDEST.mrg create mode 100644 proxmox/bkpcrit-proxmox.sh create mode 100644 proxmox/bkpsys-2fsarchive.sh create mode 100644 proxmox/proxmox-enter-container.sh create mode 100644 proxmox/proxmox-refresh-ctr-templates.sh create mode 100644 proxmox/proxmox-scan-samba-server-for-shares.sh diff --git a/proxmox/BKPDEST.mrg b/proxmox/BKPDEST.mrg new file mode 100644 index 0000000..3a7d64c --- /dev/null +++ b/proxmox/BKPDEST.mrg @@ -0,0 +1,32 @@ +# bash - this is where backup tars, etc will be stored +# can be overridden b4 sourcing +#[ "$bkpdest" = "" ] && export bkpdest=/mnt/imacdual +#[ "$bkpdest" = "" ] && export bkpdest=/zsg25lap1 + +#[ "$bkpdest" = "" ] && export bkpdest=/mnt/imac5 +[ "$bkpdest" = "" ] && export bkpdest=/mnt/seatera4-xfs + +[ `echo $bkpdest |grep -c "/mnt/"` -gt 0 ] && mount $bkpdest # mount if not ZFS! +[ `echo $bkpdest |grep -c "/media/"` -gt 0 ] && mount $bkpdest # mount if not ZFS! + +# from failexit.mrg +function failexit () { + echo '! Something failed! Code: '"$1 $2" # code # (and optional description) + exit $1 +} + + +[ -e "$bkpdest/NOTHERE" ] && failexit 99 "$bkpdest NOTHERE -- NOT MOUNTED" +# "If" checking for NOTHERE file... + +chkmount=`df |grep -c $bkpdest` +[ $chkmount -gt 0 ] || failexit 99 "$bkpdest NOT MOUNTED" + +# NOTE code 199 is generally could not cd to dir + + +myhn=`hostname` +#export BKPCRITD="$bkpdest/notshrcompr/bkpcrit-$myhn--fryserver--linux-xubuntu1404LTS-64--sdX1" +#export BKPHOMED="$bkpdest/notshrcompr/bkp-home" +#export BKPSYSD="$bkpdest/notshrcompr/bkpsys-$myhn" #--linux-xubuntu1404LTS-64--sdX1" +#export BKPSYSFSARCD=$BKPSYSD diff --git a/proxmox/bkpcrit-proxmox.sh b/proxmox/bkpcrit-proxmox.sh new file mode 100644 index 0000000..bdc6652 --- /dev/null +++ b/proxmox/bkpcrit-proxmox.sh @@ -0,0 +1,157 @@ +#!/bin/bash +# Backup critical files (hopefully) + +# Highly recommended to run this before doing ANY system updates/upgrades +# NOTE - BKPCRIT DESTINATION SHOULD NOT BE ON THE SAME DISK AS ROOT!! +# DEPENDS: lzop + +#fixresolvconf + +# xxx TODO EDITME +primaryuser=dave + +source /root/bin/boojum/BKPDEST.mrg # now provides mount test +drive=$bkpdest/notshrcompr + +source /etc/os-release + +# xxx TODO EDITME - set 1 if dest is ZFS compressed (lz4,zstd) +comprdest=0 +if [ "$comprdest" = "1" ]; then + taropts="-cpf "; tarsfx="tar" +else +# taropts="--use-compress-program lzop -cpf " + taropts="--lzop -cpf "; tarsfx="tar.lzop" +fi + +rootpartn=$(df / |tail -n 1 |awk '{print $1}') # /dev/sde1 +rootpedit=$(echo ${rootpartn##*/}) # strip off beginning, and last slash: sde1 +#dest="$drive/notshrcompr/bkpcrit-$myhn--fryserver--linux-xubuntu1404LTS-64--$rootpedit" #sdX1" +dest="$drive/bkpcrit-$myhn--$rootpedit" #sdX1 +# xxx TODO EDITME +echo $dest # = PK + +mkdir -pv $dest +chmod 750 $dest # drwxr-x--- + +tdate=$(date +%Y%m%d) # 19990909 + +# Copy this bkp script to bkpdest +cp -v $0 $dest +cp -v ~/localinfo.dat $dest +[ -e /etc/inittab ] && cp -v /etc/inittab $dest +cp -v /etc/fstab $dest +cp -v /tmp/smartctl.txt $dest +cp -v /tmp/fdisk-l.txt $dest/fdisk-l-$tdate.txt + +echo 'o Clearing old files' + # !! find bkp-gz, bkp-bz2 and flist files more than ~2 weeks old and delete + cd $dest && \ + find $dest/* \( -name "*.txt" -o -name "flist*" \) -type f -mtime +15 -exec /bin/rm -v {} \; +# find $dest/* \( -name "*.txt" -o -name "bkp*bz2" -o -name "flist*" \) -type f -mtime +20 -exec /bin/rm -v {} \; + + +# document system state +mount |egrep -v 'tmpfs|cgroup' |column -t >> $dest/fdisk-l-$tdate.txt # xxx 2017.0218 +df -hT > $dest/df-h.txt # added 2016.april +df -T -x{tmpfs,usbfs} > $dest/df-$tdate.txt # nice to have non-h df as well + +# removed 2016.0319, not using lvm +#vgdisplay -v > $dest/vgdisplay-v-$tdate.txt + +# xxx TODO editme +distro="debian" +testd=$(grep ID_LIKE /etc/os-release |awk -F\" '{print $2}') # rhel fedora +testd=${testd// /-} # bash inline sed, replace space with dash +[ "$testd" = "" ] || distro="$testd" + +tar $taropts $dest/bkp-boot--$distro.$tarsfx /boot + +tar $taropts $dest/bkp-ETC--$distro.$tarsfx /etc + +tar $taropts $dest/bkp-NXETC--$distro.$tarsfx /usr/NX/etc +tar $taropts $dest/bkp-NXSHARE--$distro.$tarsfx /usr/NX/share +tar $taropts $dest/bkp-NXVAR--$distro.$tarsfx /usr/NX/var + +# this can probably be skipped with udev auto-dev population, but may come in handy on older platforms +tar $taropts $dest/bkp-DEV--$distro.$tarsfx /dev + +tar $taropts $dest/bkp-rootshomedirectory--$distro.$tarsfx /root + +tar $taropts $dest/bkp-usr-local-bin--$distro.$tarsfx /usr/local/bin /usr/local/sbin +#tar $taropts $dest/bkp-usr-local-sbin-$distro.$tarsfx /usr/local/sbin + +tar $taropts $dest/bkp-var-dpkg-status.$tarsfx /var/lib/dpkg +tar $taropts $dest/bkp-var-dpkg-backups.$tarsfx /var/backups +tar $taropts $dest/bkp-var-cache-apt-backups.$tarsfx /var/cache/apt + +# proxmox +tar $taropts $dest/bkp-var-lib-vz.$tarsfx /var/lib/vz +tar $taropts $dest/bkp-var-lib-pve-cluster.$tarsfx /var/lib/pve-cluster + + +# rhel-related distros +tmp=/var/cache/yum; [ -e "$tmp" ] && tar $taropts $dest/bkp-var-cache-yum--$distro.$tarsfx $tmp +tmp=/var/lib/rpm; [ -e "$tmp" ] && tar $taropts $dest/bkp-var-lib-rpm--$distro.$tarsfx $tmp +tmp=/var/lib/yum; [ -e "$tmp" ] && tar $taropts $dest/bkp-var-lib-yum--$distro.$tarsfx $tmp +tmp=/var/log/secure; [ -e "$tmp" ] && tar $taropts $dest/bkp-var-log-secure--$distro.$tarsfx $tmp /var/log/yum.log + + +tar $taropts $dest/bkp-$primaryuser-src.$tarsfx /home/$primaryuser/src +tar $taropts $dest/bkp-$primaryuser-bin.$tarsfx /home/$primaryuser/bin + + +# Dotfiles +#cd /root +#tar cpvzf $dest/bkp-root-dotfiles--restore-locally$tarsfx .[^.]* + +# thunderbird is just email, goes in bkphome +# NOTE - to see size of hidden dirs: du -hs .[^.]* # REF: http://superuser.com/questions/342448/du-command-does-not-parse-hidden-directories +cd /home/$primaryuser + +# --exclude='.thunderbird' \ +tar \ + --exclude='.kde/share/thumbnails' \ + --exclude='.kde/share/cache' \ + --exclude=".pan/*" \ + --exclude='.gqview/thumbnails' \ + --exclude='.thumbnails' \ + --exclude='.opera/cache4' \ + --exclude='.opera/thumbnails' \ + --exclude=".cache/*" \ + --exclude=".mozilla/firefox/*" \ + --exclude=".moonchild productions/pale moon/*" \ + --exclude='..' \ + $taropts $dest/bkp-$primaryuser-dotfiles--restore-locally.$tarsfx .[^.]* + +# --exclude=".mozilla/firefox/*.default/Cache*" \ + +#sync + +ls $dest -alh +df -hT $drive +echo $dest +echo "$(date) - $0 done" + +exit; + + +2021.april mod for redhat/rpm-based distros (not tested on SuSE) and try to auto-determine distro type + +Copyright (C) 1999, 2000 and beyond David J Bechtel + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + The GNU Copyleft
diff --git a/proxmox/bkpsys-2fsarchive.sh b/proxmox/bkpsys-2fsarchive.sh new file mode 100644 index 0000000..da61cc8 --- /dev/null +++ b/proxmox/bkpsys-2fsarchive.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Intention: bare-metal backup and restore linux running system +# REF: http://crunchbang.org/forums/viewtopic.php?id=24268 +# REQUIRES: fsarchiver + +# TODO BOOJUM STAFF - adjust for client retention needs! +keepdays=31 + +rootdev=`df / |grep /dev |awk '{print $1}'` +rootpedit=`echo ${rootdev##*/}` # strip off beginning, and last slash: sde1 + +bkpdate=`date +%Y%m%d` + +source /root/bin/boojum/BKPDEST.mrg # now provides mount test +dest=$bkpdest +ddir=$dest/notshrcompr/bkpsys-$myhn + +source /etc/os-release + +mkdir -pv $ddir +chmod 750 $ddir # drwxr-x--- + +cd $ddir || failexit 199 "! Could not CD to $ddir" +#pwd + +#echo $rootdev $bkpdate + +outfile="bkpsys-$myhn--root-$rootpedit--$ID-$VERSION--64--$bkpdate-fsarc1-zstd.fsa" +outfile=$(echo "$outfile" |tr -d ' ') + +# TODO re-create?? +cp -v /tmp/fdisk-l.txt $ddir +cp -v /tmp/smartctl.txt $ddir +cp -v ~/bin/`basename $0` $ddir +cp -v ~/bin/boojum/RESTORE-fsarchive-root.sh $ddir + +# xxx added 2017.0218 +# free up some space 1st +# http://bashshell.net/utilities/find-with-multiple-expressions/ +# find with OR == works +##cd /mnt/bigvaitera/bkpsys-p3300-linux-mint--ubuntu11-64--sdX1 && \ +## find `pwd`/* \( -name "bkp*gz" -o -name "flist*" \) -type f -mtime +20 -exec ls -alk {} \; +#cd $pathh && find $pathh/* -type f -mtime +28 -exec rm {} \; + +# !! find bkp-gz, bkp-bz2 and flist files more than keepdays old and delete +cd $ddir && \ + find $ddir/* \( -name "bkp*fsa" -o -name "flist*" \) -type f -mtime +$keepdays -exec /bin/rm -v {} \; + +date +echo "o $0 - backing up ROOT" +df -hT / $bkpdest + +echo "Backing up EFI partition if it exists" +[ $(df |grep -c /boot/efi) -gt 0 ] && dd if=$(df /boot/efi |grep -v ilesystem |awk {'print $1'}) of=$ddir/boot-efi.dd bs=1M + +numproc=$(nproc --ignore=1) +# -Zstd not supported on deepin xxx 2019.0416 +#time fsarchiver -o -A -z 1 -j 2 savefs \ +# -Z +time fsarchiver -o -A -Z 1 -j 6 savefs \ + $ddir/$outfile \ + $rootdev + +cd $ddir +echo "`date` - Starting flist in BG" +fsarchiver archinfo $outfile 2> flist--$outfile.txt & + +ls -lh $ddir/* +echo "$0 done - `date`" + +exit; + + +HOWTO restore: +# time fsarchiver restfs /zredtera1/dv/backup-root-sda1--fryserver--ubuntu1404--`date +%Y%m%d`-fsarc1.fsa id=0,dest=/dev/sdf1 +Statistics for filesystem 0 +* files successfully processed:....regfiles=159387, directories=25579, symlinks=49276, hardlinks=25, specials=108 +* files with errors:...............regfiles=0, directories=0, symlinks=0, hardlinks=0, specials=0 +real 4m26.116s +( 3.9GB ) + +# mount /dev/sdf1 /mnt/tmp2 + +# grub-install --root-directory=/mnt/tmp2 /dev/sdf +# mount -o bind /dev /mnt/tmp2/dev; mount -o bind /proc /mnt/tmp2/proc; mount -o bind /sys /mnt/tmp2/sys + +# chroot /mnt/tmp2 /bin/bash +# update-grub +[[ +Generating grub configuration file ... +Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported. +Found linux image: /boot/vmlinuz-4.2.0-36-generic +Found initrd image: /boot/initrd.img-4.2.0-36-generic +Found linux image: /boot/vmlinuz-3.19.0-25-generic +Found initrd image: /boot/initrd.img-3.19.0-25-generic +Found memtest86+ image: /boot/memtest86+.elf +Found memtest86+ image: /boot/memtest86+.bin +Found Ubuntu 14.04.4 LTS (14.04) on /dev/sda1 +done +]] + +# grub-install /dev/sdf # from chroot + +^D +# umount /mnt/tmp2/* + +# DON'T FORGET TO COPY /home and adjust fstab for swap / home / squid BEFORE booting new drive! +# also adjust etc/network/interfaces , getdrives-byid , etc/rc.local , etc/hostname , etc/hosts , etc/init/tty11 port (home/cloudssh/.bash_login) + + +# umount /mnt/tmp2/* +# umount /mnt/tmp2 + +================================= + +CHECKLIST for new box: + diff --git a/proxmox/proxmox-enter-container.sh b/proxmox/proxmox-enter-container.sh new file mode 100644 index 0000000..51b8878 --- /dev/null +++ b/proxmox/proxmox-enter-container.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# provide container number as arg to get root +pct enter $1 +date + +exit; diff --git a/proxmox/proxmox-refresh-ctr-templates.sh b/proxmox/proxmox-refresh-ctr-templates.sh new file mode 100644 index 0000000..4ca2957 --- /dev/null +++ b/proxmox/proxmox-refresh-ctr-templates.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +pveam update +pveam list local # storage name + +# useful if we downloaded a 3rd-party template diff --git a/proxmox/proxmox-scan-samba-server-for-shares.sh b/proxmox/proxmox-scan-samba-server-for-shares.sh new file mode 100644 index 0000000..8816087 --- /dev/null +++ b/proxmox/proxmox-scan-samba-server-for-shares.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# 10gbit net - prompts for password +pvesm scan cifs macpro-10gd --username dave-imac5 --password