mirror of
https://github.com/kneutron/ansitest.git
synced 2025-01-16 04:42:55 +08:00
Add files via upload
This commit is contained in:
parent
279e113fe9
commit
526b12fd71
29
VIRTBOX/BKPDEST.mrg
Normal file
29
VIRTBOX/BKPDEST.mrg
Normal file
@ -0,0 +1,29 @@
|
||||
# bash - this defines where backup tars, etc will be stored
|
||||
# this lives in /root/bin/boojum - multiple scripts look for it there and source it, so dont do 'exit' at end
|
||||
|
||||
#export bkpdest=/mnt/milterausb3
|
||||
# if calling script has an override, we still provide value by checking for mount
|
||||
#[ "$bkpdest" = "" ] && export bkpdest=/mnt/imacdual
|
||||
#[ "$bkpdest" = "" ] && export bkpdest=/mnt/imac5 ## shared drive
|
||||
[ "$bkpdest" = "" ] && export bkpdest=/zsg25lap1
|
||||
# xxx TODO EDITME - should not be same disk as root!
|
||||
|
||||
[ $(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 under non-mounted dir... 0ldsk00l hax
|
||||
|
||||
chkmount=$(df |grep -c $bkpdest)
|
||||
[ $chkmount -gt 0 ] || failexit 99 "$bkpdest NOT MOUNTED"
|
||||
|
||||
# NOTE code 199 is generally could not cd to dir
|
||||
|
||||
export myhn=$(hostname)
|
135
VIRTBOX/bkpcrit.sh
Normal file
135
VIRTBOX/bkpcrit.sh
Normal file
@ -0,0 +1,135 @@
|
||||
#!/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
|
||||
|
||||
# xxx TODO - 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/bkpcrit-$myhn--linux-xubuntu1404LTS-64--sdX1"
|
||||
#dest="$drive/notshrcompr/bkpcrit-$myhn--fryserver--linux-xubuntu1404LTS-64--$rootpedit" #sdX1"
|
||||
dest="$drive/bkpcrit-$myhn--linux-antix-64--$rootpedit" #sdX1 # xxx TODO EDITME
|
||||
echo $dest # = PK
|
||||
#read
|
||||
|
||||
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"
|
||||
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
|
||||
|
||||
tar $taropts $dest/bkp-DEV-$distro.$tarsfx /dev
|
||||
|
||||
tar $taropts $dest/bkp-root-$distro.$tarsfx /root
|
||||
|
||||
tar $taropts $dest/bkp-usr-local-bin-$distro.$tarsfx /usr/local/bin
|
||||
|
||||
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
|
||||
|
||||
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 -h $drive
|
||||
echo $dest
|
||||
echo "$(date) - $0 done"
|
||||
|
||||
exit;
|
||||
|
||||
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.
|
||||
|
||||
<a href="http://www.gnu.org/copyleft/gpl.html"> The GNU Copyleft </a><br>
|
48
VIRTBOX/bkphome.sh
Normal file
48
VIRTBOX/bkphome.sh
Normal file
@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
# DEPENDS: pv, tar, flist.sh, /root/bin/boojum/BKPDEST.mrg (up to date with valid destination dir)
|
||||
|
||||
source /root/bin/boojum/BKPDEST.mrg # now provides mount test
|
||||
bkpath=$bkpdest/notshrcompr
|
||||
|
||||
pathh="$bkpath/bkp-home"
|
||||
mkdir -p -v $pathh
|
||||
cd $pathh || failexit 199 "! Could not CD to $pathh";
|
||||
ls -lh
|
||||
|
||||
bkpdate=$(date +%Y%m%d)
|
||||
bkpfname="bkp-home--$myhn--NORZ--$bkpdate"
|
||||
|
||||
# free up some space 1st
|
||||
# http://bashshell.net/utilities/find-with-multiple-expressions/
|
||||
# find with OR == works
|
||||
|
||||
#cd $pathh && find $pathh/* -type f -mtime +28 -exec rm {} \;
|
||||
# !! find bkp-gz and flist files more than 20 days old and delete
|
||||
# SKIP, shared dir with multiple home sources
|
||||
#echo 'o Autocleaning old bkps for free space'
|
||||
#cd $pathh && \
|
||||
# find $pathh/* \( -name "bkp*gz" -o -name "bkp*bz2" -o -name "bkp*lzop" -o -name "flist*" \) -type f -mtime +20 -exec /bin/rm -v {} \;
|
||||
|
||||
echo "==Backing up HOME to $pathh"
|
||||
df -hT /home $bkpdest
|
||||
|
||||
# comprdest
|
||||
time tar \
|
||||
-cpf - /home/* \
|
||||
| pv -t -r -b -W -i 2 -B 50M \
|
||||
> $bkpfname.tar
|
||||
# | lzop \
|
||||
# > $bkpfname.tar.lzop
|
||||
|
||||
# -cpf - /home/* |gzip -2 > $bkpfname.tar1.gz
|
||||
|
||||
ls -lh
|
||||
|
||||
#echo $pathh
|
||||
#time sync
|
||||
|
||||
flist.sh &
|
||||
#time tar tzvf $bkpfname.tar1.gz > flist--$bkpfname.txt &
|
||||
pwd
|
||||
echo "$0 done - $(date)"
|
75
VIRTBOX/bkpsys-2fsarchive.sh
Normal file
75
VIRTBOX/bkpsys-2fsarchive.sh
Normal file
@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Intention: bare-metal backup and restore linux running system (root), quite handy for restoring to VM
|
||||
# REF: http://crunchbang.org/forums/viewtopic.php?id=24268
|
||||
|
||||
# DEPENDS: fsarchiver, /root/bin/boojum/BKPDEST.mrg (up to date with a valid destination dir)
|
||||
|
||||
# NOTE define a PATH here if you want to run from CRON
|
||||
# NOTE if you're running stuff like mysql or anything making live updates, you should stop the related service
|
||||
|
||||
keepdays=31
|
||||
|
||||
rootdev=$(df / |grep /dev |awk '{print $1}')
|
||||
bkpdate=$(date +%Y%m%d)
|
||||
|
||||
# xxx TODO EDITME vv edit BKPDEST to define your backup destination dir before running this
|
||||
source /root/bin/boojum/BKPDEST.mrg # now provides mount test
|
||||
dest=$bkpdest/notshrcompr
|
||||
|
||||
ddir=$dest/bkpsys-$myhn
|
||||
mkdir -pv $ddir
|
||||
chmod 750 $ddir # drwxr-x---
|
||||
cd $ddir || failexit 199 "! Could not CD to $ddir"
|
||||
|
||||
# need shorter filename for UDF restores 2017.0827
|
||||
#outfile=bkpsys--p2300m-dell-1550-studio--backup-root-sda6--antix16-64--debian-no-systemd--1tb-drive--$bkpdate-fsarc1.fsa
|
||||
outfile="bkpsys-$myhn-64-debstable10-$bkpdate-fsarc-ZSTD.fsa"
|
||||
# xxx TODO ^^ EDITME
|
||||
|
||||
cp -v /tmp/fdisk-l.txt $ddir
|
||||
cp -v /tmp/smartctl.txt $ddir
|
||||
cp -v $0 $ddir
|
||||
cp -v ~/bin/boojum/RESTORE-fsarchive-root.sh $ddir
|
||||
# copy restore script to backup dir, goes with mkrestoredvdiso.sh
|
||||
|
||||
# NOTE autoclean !! find bkps and flist files more than XX days old and delete
|
||||
cd $ddir && \
|
||||
find $ddir/* \( -name "bkp*fsa" -o -name "flist*" \) -type f -mtime +$keepdays -exec /bin/rm -v {} \;
|
||||
|
||||
echo "o $0 - backing up ROOT"
|
||||
df -hT / $dest
|
||||
date
|
||||
numproc=$(nproc --ignore=1)
|
||||
#time fsarchiver -v -o -A -z 1 -j 2 savefs \
|
||||
# NOTE older / LTS distros may need to use lower-case -z since the package ver may not support zstd
|
||||
time fsarchiver -o -A -Z 1 -j $numproc savefs \
|
||||
$ddir/$outfile \
|
||||
$rootdev
|
||||
|
||||
cd $ddir
|
||||
fsarchiver archinfo $outfile 2> flist--$outfile.txt
|
||||
|
||||
ls -lh $ddir/*
|
||||
echo "$(date) - $0 done"
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
NOTE this script does NOT cover zfs-as-root on linux!
|
||||
run bkpcrit.sh for that before doing any update/upgrades
|
||||
|
||||
HOWTO restore:
|
||||
# time fsarchiver restfs backup-root-sda1--fryserver--ubuntu1404-*-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 )
|
||||
|
||||
PROTIP fsarchiver can restore to a different filesystem OTF such as xfs, should Just Work as long as you edit fstab
|
||||
after restore (make sure no filesystem-specific mount options such as {commit,errors=remount-ro};
|
||||
+ changing ext4 to auto may also work)
|
||||
and before booting restored system / VM
|
||||
|
||||
NOTE if you have a separate /home (and you should) you will need to restore that as well into the VM b4 booting it
|
74
VIRTBOX/flist.sh
Normal file
74
VIRTBOX/flist.sh
Normal file
@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Go thru .tar.gz, .tar.bz2 in dir and list them to flist-file
|
||||
# This generally lives in /usr/local/bin since non-root can call it
|
||||
# DEPENDS: gzip, bzip2, lzop, tar
|
||||
|
||||
function process () {
|
||||
args=$*
|
||||
echo $args
|
||||
|
||||
# if doing rezip, renice bzip2
|
||||
renice +1 $(pidof bzip2) 2>/dev/null
|
||||
|
||||
# Preserve existing output
|
||||
if [ -e "flist--$bn.txt" ]; then
|
||||
echo "* Skipped $bn"
|
||||
else
|
||||
time $compr -cd $args |tar tvf - > flist--$bn.txt
|
||||
fi
|
||||
}
|
||||
|
||||
# If compare string not match any actual filename, move on
|
||||
for i in *.tar.gz; do
|
||||
[ "$i" == "*.tar.gz" ] && break;
|
||||
bn=`basename $i .tar.gz`
|
||||
compr=gzip
|
||||
process $i
|
||||
done
|
||||
|
||||
for i in *.tar1.gz; do
|
||||
[ "$i" == "*.tar1.gz" ] && break;
|
||||
bn=`basename $i .tar1.gz`
|
||||
compr=gzip
|
||||
process $i
|
||||
done
|
||||
|
||||
for i in *.tgz; do
|
||||
[ "$i" == "*.tgz" ] && break;
|
||||
bn=`basename $i .tgz`
|
||||
compr=gzip
|
||||
process $i
|
||||
done
|
||||
|
||||
for i in *.tar.bz2; do
|
||||
[ "$i" == "*.tar.bz2" ] && break;
|
||||
bn=`basename $i .tar.bz2`
|
||||
compr=bzip2
|
||||
process $i
|
||||
done
|
||||
|
||||
for i in *.tar.lzop; do
|
||||
[ "$i" == "*.tar.lzop" ] && break;
|
||||
bn=`basename $i .tar.lzop`
|
||||
compr=lzop
|
||||
process $i
|
||||
done
|
||||
|
||||
for i in *.tar1.lzop; do
|
||||
[ "$i" == "*.tar1.lzop" ] && break;
|
||||
bn=`basename $i .tar1.lzop`
|
||||
compr=lzop
|
||||
process $i
|
||||
done
|
||||
|
||||
for i in *.tar; do
|
||||
[ "$i" == "*.tar" ] && break;
|
||||
bn=`basename $i .tar`
|
||||
compr=""
|
||||
# process $i
|
||||
time tar tvf $i > flist--$bn.txt
|
||||
done
|
||||
|
||||
# TODO zstd
|
||||
# 2014(?)-2021 Dave Bechtel
|
Loading…
x
Reference in New Issue
Block a user