Gitlab Community Edition Instance

Commit 0f498b68 authored by Bjoern Nachtwey's avatar Bjoern Nachtwey
Browse files

initial coding and adding some more approaches

parent abcc4e51
#! /bin/bash
##############################################################################
#
# backup-SNFS.sh
#
# script for backing up GWDG's stornext filesystems using different approaches
# and writing RC to "<$FS>.backup_rc"
#
# (C) 2022 GWDG Göttingen, Bjørn Nachtwey
# mailto:bjoern.nachtwey@gwdg.de
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# changelog
# date version remark
# 2022-03-xx 0.0 initial coding just using file list
# 2022-03-16 0.1 add some more approaches
# get current date
today=$(date +"%F");
fsname=$1; # Name of Filesystem as mounted below "/stornext"
bpath=/stornext/$fsname # path to it
kind=$2; # switch for using "-incrbydate" option
optfile=/StorNext-Backup/opt/$fsname.opt
daysback=10
export LANG=en_US
cd /StorNext-Backup/$fsname/
# presched operations
rm -f /StorNext-Backup/log/$fsname.sched.log
## do backup
case "$kind" in
I) # Standard incremental backup
/opt/tivoli/tsm/client/ba/bin/dsmc i -optfile=$optfile
# get RC
rc=$?;
;;
B) # incremental backup with "-incrbydate"
/opt/tivoli/tsm/client/ba/bin/dsmc i -incrbydate -optfile=$optfile
# get RC
rc=$?;
;;
D) # use dsmci.pl for parallel backup
perl -f /StorNext-Backup/bin/dsmci.pl
rc=$?;
;;
F) # use filelist backup
infile=$today.reduced
newfile=$today.new
chgfile=$today.chg
rnnfile=$today.rnn
ronfile=$today.ron
delfile=$today.del
incfile=$today.inc
expfile=$today.exp
# cat last three day's changelist to input file
cat $(find $bpath -maxdepth 1 -name "*_chglst.json" -mtime -$daysback) > $infile
# new files
grep -A2 '"CREATE"' $infile | grep '"pathname"' | sed -e 's/,$//' | awk -F '\"' '{print $4}' | grep -v "^/[0-9]*$" | sed -e "s#^#$bpath#" | sort | uniq > $newfile
# changed files
grep -A2 '"MODIFY"' $infile | grep '"pathname"' | sed -e 's/,$//' | awk -F '\"' '{print $4}' | grep -v "^/[0-9]*$" | sed -e "s#^#$bpath#" | sort | uniq > $chgfile
# renamed new files
grep -A3 '"RENAME"' $infile | grep '"newname"' | sed -e 's/,$//' | awk -F '\"' '{print $4}' | grep -v "^/[0-9]*$" | sed -e "s#^#$bpath#" | sort | uniq > $rnnfile
# renamed old files
grep -A2 '"RENAME"' $infile | grep '"pathname"' | sed -e 's/,$//' | awk -F '\"' '{print $4}' | sed -e "s#^#$bpath#" | sort | uniq > $ronfile
# deleted files
grep -A2 '"REMOVE"' $infile | grep '"pathname"' | sed -e 's/,$//' | awk -F '\"' '{print $4}' | sed -e "s#^#$bpath#" | sort | uniq > $delfile
# files be processed with "i", but filter for files on the most top level
cat missed_files $newfile $chgfile $rnnfile | sort | uniq > $incfile
# files to be procced with "expire"
cat $delfile $ronfile | sort | uniq > $expfile
# run Backups
starttime=$(date +%s.%N)
/opt/tivoli/tsm/client/ba/bin/dsmc INCremental -filelist=$incfile -optfile=$optfile
# get backup rc
rc=$?;
grep "ANS4037E" /StorNext-Backup/log/$fsname.error.log | cut -f2 -d"'" > missed_files
# run File Expiration
/opt/tivoli/tsm/client/ba/bin/dsmc EXPire -filelist=$expfile -optfile=$optfile -noprompt
# skip expire rc
# get runtime of all
duration=$(echo "$(date +%s.%N) - $starttime" | bc)
# get & write stats
echo $today "; " $rc $(wc -l $today.??? | awk '{print "; " $1 }' | tr "\n" " ") ";" $duration >> cfl.stats
# remove temporary files
rm -f $today.*
;;
*) # fallback to standard incremental if nothing is set
/opt/tivoli/tsm/client/ba/bin/dsmc i -optfile=$optfile
# get RC
rc=$?;
;;
esac
# postsched operations
## copy rc to FS
echo $rc > $bpath/.backup_rc
## rotate log and compress
if [ -s /StorNext-Backup/log/$fsname.sched.log ]
then
mv /StorNext-Backup/log/$fsname.sched.log /StorNext-Backup/log/$today-$fsname.sched.log
touch /StorNext-Backup/log/$fsname.sched.log
bzip2 /StorNext-Backup/log/$today-$fsname.sched.log
fi
if [ -s /StorNext-Backup/log/$fsname.error.log ]
then
mv /StorNext-Backup/log/$fsname.error.log /StorNext-Backup/log/$today-$fsname.error.log
touch /StorNext-Backup/log/$fsname.error.log
bzip2 /StorNext-Backup/log/$today-$fsname.error.log
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment