1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
|
#!/bin/sh
#This is where all history files are stored /////
logpath=/var/adm/dump
if [ -z $1 ] || [ $1 = -h ] || [ $1 = --help ]
then
cat <<EOHELP
# This script implements incremental and/or compressed
# and/or encrypted backups using afio, gzip and pgp/gnupg on floppies
# or tapes or other devices.
# Make sure that you have all the priviledges needed to access your files
# and devices or start this script as root.
# USAGE: secbak <level> [<label>]"
# <level> = 0 : fullbackup"
# <level> = [1-9] : incremental backup"
#
#
# EXAMPLE: secbak 5 Tape3-
# Grep for "////" to configure this script for your environnement.
# In the function CHOOSEFILE you decide "WHAT" has to be backuped und
# in START you determine "HOW" and "WHERE".
# For more detailed information type:
# secbak --help
EOHELP
if [ -z $1 ]
then
exit 0
fi
cat <<EOHELP
# OUTPUT and LOGFILES:
#secbak writes log-files in the \$logpath directory that may look like:
#
# a) Logfiles after normal termination of afio:
# Tape3-1234starttime.level6
# : the ctime stamp of this file is used in later
# : backups for finding newer files
# Tape3-1234filelist.level6.gz
# : a list of
# : all files archived at the time indicated by
# : the ctime stamp of Tape3-1234starttime.level6
# : (compressed with gzip)
# Tape3-1234afiolog.level6.gz
# : afios messages
# : (compressed with gzip)
# b) Logfiles after errors
# Tape3-2345starttimeNOT-OK.level6
# : due to an error secbak hasn't terminated. The backup
# : may be uncomplete
# Tape3-1234filelistNOT-OK.level6
# : a list of
# : all files archived at the time indicated by
# : the ctime stamp of Tape3-1234starttimeNOT-OK.level6
# : After a broken pipe this list contains usually more
# : files than has been actually saved.
# Tape3-2345afiologNOT-OK.level6
# : afios messages
# c) general logging:
# backuphistory.txt
# : All output of secbak is appended to
# : "backuphistory.txt". You will find there
# : information about each backup concerning
# : time, error messages, the parameters afio was
# : called with (including the device the archive
# : archive was written on) and other usefull things.
#
# RESTORING
# You don't need this script to restore the contents of the archive-files.
# You only need having afio installed and eventually gzip, pgp or gpg.
# Since afio is compatible with cpio you can also une cpio to retore your
# archives. In this case it may be necessary to unzip the files manually.
# This may be usefull after a disc crash.
# You should invoke afio with the parameters corresponding to the ones you
# have used for backup. See the START-function in this script.
# Some examples can be found in the "secbakrestore" script that
# comes with "secbak".
# To rebuild the latest status of your disk
# start restoring the latest level 0 backup,
# then all level 1 backups, up to the
# highest level you find in the $logpath directory.
# Keep in mind that incremental archives do not
# contain a list of in the meantime deleted files.
# REQUEST FOR HELP
#
# This helptext and the following messages (english spelling and expression)
# need to be revised by a native speaker.
EOHELP
exit 0
fi
# HISTORY
# Script written by Jens Getreu
# New feature in secbak 1.4:
# secbak accepts a new second optional parameter: <label>
#
# usage: secbak <level> [<label>]
# example: secbak 5 Tape3-
#
# The paramater label only affects the names of the logfiles given
# to the current job.
# The above example performs a level 5 backup and writes its logfiles
# in files of style: Tape3-id3456 ... .level5
# Jens Getreu
# Version 1.5
# secbak 1.4 stopped in case of a return code other then 0.
# secbak 1.5 ignores the return code of afio, but tries to
# grep error messages in it's logfile instead.
# Jens Getreu
# Version 1.6
# All pgp second input stream handling is transfered from the
# BACKMEUP-function to the start function.
# All pgp related stuff is now kept together.
# The pgp examples now use the afio option -3 introduced in
# afio 2.4.6.
# Examples for encryption with gpg are also introduced in
# function "START" within 1.6.
#
# The find output is now logged in ...filelist.level...
# while afios messages are still logged in ...afiolog.level...
#
# afios return-code seems to be more relieable now.
# secback 1.6 refers to it in order to decide whether
# or not the backup has been successfull.
# 16.9.1999 Jens Getreu
# Version 1.7
# Bug in pgp commandline in START removed.
# The shell expanded "$PGPPASSFD<$passphrasefile" to "3 </foo/foofoo"
# instead of "3</foo/foofoo" what was intended.
# So I replaced "$PGPPASSFD<$passphrasefile" with "3<$passphrasefile".
# Thanks to Koen Holtman for having discoverd this.
# 23.9.1999 Jens Getreu
########################## CHOOSEFILES ##########################
########## begin of uncomment one example only
#CHOOSEFILES ()
#{
### adapt this to fit your application /////
### $findadd has to be be added at the end of each find command !!!
# find /boot /etc /home /opt /root /usr/local \
# /var/spool /var/log /var/adm/dump $findadd \
# |egrep -v '/Sicherungskopie|~$|/~|\$$|\.bak$|\.tmp$|\.tmpdir/' -
#}
CHOOSEFILES ()
{
## adapt this to fit your application /////
## $findadd has to be be added at the end of each find command !!!
( find /usr/local/bak /etc\
/home/getreu/JENS_DATEN/DOKUMENTE $findadd
find /home/getreu/ /home/getreu/Mail /home/getreu/Emailadressen \
/root /root/bin -maxdepth 1 $findadd) \
|egrep -v '/Sicherungskopie|~$|/~|\$$|\.bak$|\.tmp$|\.tmpdir$' -
}
########## end of uncomment one example only
##################### end of CHOOSEFILES #####################
########################## BACKMEUP ###########################
BACKMEUP ()
{
# There is probably no need to change anything in this function
case $level in
0) # If it is a level 0 dump simply dump everything...
findadd=''
;;
[1-9])
# Get the date of the most recent dump with the highest level <= $level]
prevdump=$(ls --sort=time --format=single-column \
$logpath/*starttime.level[0-$level]| head --lines=1 \
2>/dev/null)
if [ -z $prevdump ]
then
echo "WARNING No lower level backup than $level!"
echo Trying backup level 0.
level=0
START
echo ')'
exit 0
fi
# Otherwise dump only stuff newer...
echo "Incremental level $level backup. Previous was:"
echo -e "\t $prevdump"
findadd="-cnewer $prevdump"
;;
esac
echo "Writing filelist in:"
echo -e "\t $logpath/${LABEL}id$$filelistNOT-OK.level${level}"
echo "and afios (error) messages in:"
echo -e "\t $logpath/${LABEL}id$$afiologNOT-OK.level${level}"
echo $1 >"$logpath/${LABEL}id$$afiologNOT-OK.level${level}"
#save startime in timestamp of file
echo > "$logpath/${LABEL}id$$starttimeNOT-OK.level$level"
echo "Starting Backup ..."
echo \"$1\"
error=false
CHOOSEFILES |tee $logpath/${LABEL}id$$filelistNOT-OK.level${level} \
|nice -n -15 $1 \
1>>$logpath/${LABEL}id$$afiologNOT-OK.level${level} \
2>&1 \
|| error=true
if [ $error = true ]
then echo '***ERRORs occurred!' \
'Your backup was probably NOT successfull***'
echo "afios last 5 messages:"
grep '^afio:' "$logpath/${LABEL}id$$afiologNOT-OK.level$level" \
| tail --lines 5
echo ')'
exit 1
else echo "... Backup finished"
echo "Here are afios messages:"
grep '^afio:' "$logpath/${LABEL}id$$afiologNOT-OK.level$level"
fi
# All higher level backups are now invalidated so we delete logs
if [ $level -le 8 ]
then
# don't enclosure rm argument with ""!
rm -f $logpath/*.level[$(($level+1))-9]*
fi
echo -e "compressing\t afiologNOT-OK.level$level"\
"\t into: afiolog.level${level}.gz"
echo -e "\t and \t filelistNOT-OK.level$level"\
"\t into: filelist.level${level}.gz"
gzip -c "$logpath/${LABEL}id$$afiologNOT-OK.level$level" \
> "$logpath/${LABEL}id$$afiolog.level${level}.gz" \
&& rm -f "$logpath/${LABEL}id$$afiologNOT-OK.level$level"
gzip -c "$logpath/${LABEL}id$$filelistNOT-OK.level$level" \
> "$logpath/${LABEL}id$$filelist.level${level}.gz" \
&& rm -f "$logpath/${LABEL}id$$filelistNOT-OK.level$level"
mv "$logpath/${LABEL}id$$starttimeNOT-OK.level$level" \
"$logpath/${LABEL}id$$starttime.level$level"
}
###################end of BACKMEUP ###########################
######################## START ##############################
START ()
{
echo -e \\n "($(date) secbak version 1.7"
case $level in
0) # If it is a level 0 dump simply dump everything...
######### begin of uncomment one example only /////
### archive compressed files on a non rewinding tape
#BACKMEUP "afio -ovz -Z /dev/nst0"
### archive PGP-encrypted compressed files on a non rewinding tape
### open a second input stream for PGP
### pgp needs a tmp directory which should only be readable for root
#export TMP=/root/bin/secbak.tmpdir
#export PGPPASSFD=3
#export RANDSEED=~/.pgp/randseed.bin
#passphrasefile=$TMP/secbak.parms
#BACKMEUP "afio -ovz -Z -U -P pgp -Q -fc -Q +verbose=0
# -3 3
# /dev/nst0" \
# 3<$passphrasefile
### archive Gnu-PG encrypted compressed files on a non rewinding tape
### open a second input stream for GnuPg
#passphrasefile=/root/bin/secbak.tmpdir/secbak.parms
#BACKMEUP "afio -ovz -Z -U -P gpg -Q --symmetric
# -Q --passphrase-fd=3 -Q --no-verbose
# -Q --batch -Q --no-options -3 3
# /dev/nst0" \
# 3<$passphrasefile
###archive compressed files directly on a HD floppy
###as a multi-volume archive
BACKMEUP "afio -ovz -s1440k -Z /dev/fd0"
###archive pgp-encrypted compressed files directly on a HD floppy
###as multi-volume archive
### open a second input stream for pgp
### pgp needs a tmp directory which should only be readable for root
#export TMP=/root/bin/secbak.tmpdir
#export PGPPASSFD=3
#export RANDSEED=~/.pgp/randseed.bin
#passphrasefile=$TMP/secbak.parms
#BACKMEUP "afio -ovz -s1440k -Z -U -P pgp -Q -fc -Q +verbose=0
# -3 3
# /dev/fd0" \
# 3<$passphrasefile
###archive GnuPG-encrypted compressed files directly on a HD floppy
###as multi-volume archive
### open a second input stream for GnuPg
#passphrasefile=/root/bin/secbak.tmpdir/secbak.parms
#BACKMEUP "afio -ovz -s1440k -Z -U -P gpg -Q --symmetric
# -Q --passphrase-fd=3 -Q --no-verbose
# -Q --batch -Q --no-options -3 3
# /dev/fd0" \
# 3<$passphrasefile
######### end of uncomment one example only /////
;;
[1-9])
### Otherwise dump only stuff newer...
########## begin of uncomment one example only /////
### archive compressed files on a non rewinding tape
#BACKMEUP "afio -ovz -Z /dev/nst0"
### archiv PGP compressed encrypted files on a non rewinding tape
### open a second input stream for PGP
### pgp needs a tmp directory which should only be readable for root
#export TMP=/root/bin/secbak.tmpdir
#export PGPPASSFD=3
#export RANDSEED=~/.pgp/randseed.bin
#passphrasefile=$TMP/secbak.parms
#BACKMEUP "afio -ovz -Z -U -P pgp -Q -fc -Q +verbose=0
# -3 3
# /dev/nst0" \
# 3<$passphrasefile
### archiv Gnu-PG compressed encrypted files on a non rewinding tape
#export RANDSEED=~/.pgp/randseed.bin
#passphrasefile=/root/bin/secbak.tmpdir/secbak.parms
#BACKMEUP "afio -ovz -Z -U -P gpg -Q --symmetric
# -Q --passphrase-fd=3 -Q --no-verbose
# -Q --batch -Q --no-options -3 3
# /dev/nst0" \
# 3<$passphrasefile
### archiv compressed files in file on a floppy
mount /floppy
BACKMEUP "afio -ovz -s1440k -Z
/floppy/${LABEL}id$$afioarchive.level$level"
umount /floppy
### archive PGP- encrypted compressed files in file on floppy
### open a second input stream for PGP
### pgp needs a tmp directory which should only be readable for root
#mount /floppy
#export TMP=/root/bin/secbak.tmpdir
#export PGPPASSFD=3
#export RANDSEED=~/.pgp/randseed.bin
#passphrasefile=$TMP/secbak.parms
#BACKMEUP "afio -ovz -s1440k -Z -U -P pgp -Q -fc -Q +verbose=0
# -3 3
# /floppy/${LABEL}id$$afioarchiv.level$level" \
# 3<$passphrasefile
#umount /floppy
### archive Gnupg encrypted compressed files in file on floppy
### open a second input stream for GnuPG
#mount /floppy
#passphrasefile=/root/bin/secbak.tmpdir/secbak.parms
#BACKMEUP "afio -ovz -s1440k -Z -U -P gpg -Q --symmetric
# -Q --passphrase-fd=3 -Q --no-verbose
# -Q --batch -Q --no-options -3 3
# /floppy/${LABEL}id$$afioarchiv.level$level" \
# 3<$passphrasefile
#umount /floppy
########## end of uncomment one example only /////
;;
*) # print short help
$0
echo ')'
exit 1
;;
esac
echo ')'
}
###############end of START #############################
############## MAIN #####################################
# There is probably no need to change anything in this function
level=$1
LABEL=$2
test -d $logpath ||
if ! mkdir --parents $logpath
then
echo "ABORT!"
echo -e "\t Can\'t mkdir $logpath to store the logfiles."
echo -e "\t Please start this script as root or modify the \$logpath"
echo -e "\t definition there."
exit 1
fi
# log all output in ...
START 2>&1 | tee --append "$logpath/backuphistory.txt"
############## end of MAIN #######################
|