#!/bin/bash # #***************************************************************************** # DARsi - dar-simplifier: make full/differential backups using dar * #***************************************************************************** # Author: Christian Habermann * # christian (at) habermann-net (point) de * # Version: 1.0.0 * # Date: 9. Feb. 2004 * # * # Copyright 2004 by Christian Habermann, distributed under the terms of GPL * # * # * # History: - V1.0.0: first release * # * # * #***************************************************************************** # Description: * # This script simplifies usage of dar. dar is (c) by Denis Corbin. * # Before starting to use this script it must be configured. Make your * # settings in the section titled as "USER SETTINGS". * # Of course dar must be installed. * # * #***************************************************************************** #***************************************************************************** #***************************** USER SETTINGS ********************************* #***************************************************************************** #*** USER: Adapt the following settings to you own needs. Mendatory *** #*** are DIRLIST_INC, ARCH_PATH and USER_SETTINGS_DONE. *** # top level from where to start backups, / is a very good choice DIR_ROOT="/" # sub-trees from DIR_ROOT to be included into backups # leave it empty, if you want to do a full backup of your system # paths must be relative(!) to DIR_ROOT DIRLIST_INC="etc boot home root" # directory sub-trees excluded from backup, e.g. "-P mnt -P proc -P dev/pts" # paths must be relative(!) to DIR_ROOT, each path must have a "-P " in front of it DIRLIST_EXCL="" # files excluded from compression # set this to "" if compression is not enabled in OPT_FULL and OPT_DIFF # hint: commonly compressing videos, pictures, sounds do not make much sens, # since they are already compressed very well FILE_NOCOMPRESS="-Z *.mpg -Z *.mpeg -Z *.wmv -Z *.rm -Z *.avi -Z *.jpg -Z *.gif -Z *.png -Z *.gz -Z *.zip -Z *.bz2" # compression level (1...9): 1 is low compression/fast, 9 is max. compression/slow COMP_LEVEL=4 # dar options for full backup, default is: verbose, split at 2GByte, enable compression OPT_FULL="-v -s 1999M -z$COMP_LEVEL" # dar options for differential backup, default is: verbose, split at 2GByte, enable compression OPT_DIFF="-v -s 1999M -z$COMP_LEVEL" # dar options for listing archive's content OPT_LIST="" # dar options for extraction files OPT_EXTRACT="" # absolut path to where archives will be stored and searched, e.g.: /mnt/nfsserver ARCH_PATH="/mnt/nfsserver" # how to call DAR: give program name here, normally "dar" # But if you use the static version of dar, set DAR_PROG to "dar_static". # Path can also be added here, if DAR is not in your search path. DAR_PROG="dar" # IMPORTANT: set this to 1, else DARsi will deny to start. # This is done to ensure that user has configured this script. USER_SETTINGS_DONE=0 #*** end of user's area *** #***************************************************************************** #***************************** INITIALIZATION ******************************** #***************************************************************************** VERSION="1.0.0" PROGNAME="DARsi" SCRIPTNAME="darsi" action="" #***************************************************************************** #******************************* FUNCTIONS *********************************** #***************************************************************************** #***************************************************************************** # input: none * # output: none * #***************************************************************************** # exit script * #***************************************************************************** DSI_Exit() { exit 0 } #***************************************************************************** # input: none * # output: none * #***************************************************************************** # print short description of usage * #***************************************************************************** DSI_PrintUsage() { echo "" echo "Usage: $SCRIPTNAME --full NEW_ARCHIVE" echo " $SCRIPTNAME --diff PREVIOUS_ARCHIVE NEW_ARCHIVE" echo " $SCRIPTNAME --list ARCHIVE" echo " $SCRIPTNAME --extract ARCHIVE DEST_PATH [filelist|dirlist]" echo "" echo " $SCRIPTNAME --help" } #***************************************************************************** # input: none * # output: none * #***************************************************************************** # print help text * #***************************************************************************** DSI_PrintHelp() { echo "What is archived and where archives are stored is defined in the header" echo "of $PROGNAME, see section entitled with \"USER SETTINGS\"." echo "NOTE: Before using this script it must be configured once." echo "" echo "Make Full-Backup" echo "----------------" echo "Syntax: $SCRIPTNAME --full NEW_ARCHIVE" echo "" echo " NEW_ARCHIVE: basename of archive" echo " Add neither path nor extensions, give plain basename." echo "" echo "Make Differential-Backup" echo "------------------------" echo "Syntax: $SCRIPTNAME --diff PREVIOUS_ARCHIVE NEW_ARCHIVE" echo "" echo " PREVIOUS_ARCHIVE: basename of privously made archive" echo " This may be a full archive or a differential one." echo " Add neither path nor extensions, give plain basename." echo " NEW_ARCHIVE: basename of differential archive to be created" echo " Add neither path nor extensions, give plain basename." echo "" echo "Show Content of Archive" echo "-----------------------" echo "Syntax: $SCRIPTNAME --list ARCHIVE" echo "" echo " ARCHIVE: basename of archive" echo " Add neither path nor extensions, give plain basename." echo "" echo "Extract From Archive (Restore)" echo "------------------------------" echo "Syntax: $SCRIPTNAME --extract ARCHIVE DEST_PATH [filelist|dirlist]" echo "" echo " ARCHIVE: basename of archive" echo " Add neither path nor extensions, give plain basename." echo " DEST_PATH: path to where files should be extracted" echo " [filelist|dirlist]: list of files or directories to be extracted" echo " to the path specified in DEST_PATH." } #***************************************************************************** # input: $1: start time in seconds since 1970... * # $2: end time in seconds since 1970... * # output: none * #***************************************************************************** # Print duration of dar-operation in hour, min, sec * #***************************************************************************** DSI_PrintDuration() { local startT=$1 local endT=$2 local hour local min local sec local timediff if [ $endT -ge $startT ]; then let timediff=$endT-$startT let hour=$timediff/3600 let min=($timediff%3600)/60 let sec=$timediff%60 echo "Duration: ${hour}h ${min}m ${sec}s" else echo "internal ERROR: start time > end time" DSI_Exit fi } #***************************************************************************** # input: $1: number of parameters this script is called with * # $2 $3 $4 $5: parameters this script is called with * # output: 0: ok * # >0: error, bad set of parameter * #***************************************************************************** # Evaluate parameters. * #***************************************************************************** DSI_EvaluateParameters() { local result=0 action="$2" case "$action" in "--full") if [ "$1" -eq 2 ]; then archive="$3" if [ ! -d "$ARCH_PATH" ]; then echo "path does not exist: $ARCH_PATH" result=1 fi else result=1 fi ;; "--diff") if [ "$1" -eq 3 ]; then archive="$4" archive_prev="$3" else result=1 fi ;; "--list") if [ "$1" -eq 2 ]; then archive="$3" else result=1 fi ;; "--extract") if [ "$1" -ge 3 ]; then archive="$3" dest_dir="$4" restore_files="$5" if [ ! -d "$dest_dir" ]; then echo "destination path not found: $dest_dir" result=1 fi else result=1 fi ;; "--help") ;; *) result=1 ;; esac return $result } #***************************************************************************** #******************************* M A I N *********************************** #***************************************************************************** echo "$PROGNAME V$VERSION" # exit if user has not done settings and want to do anything else then # showing help if [ $USER_SETTINGS_DONE -eq 0 ] && [ "$1" != "--help" ]; then echo "ERROR: It seems that $PROGNAME is not configured. Please adapt this" echo " script to your own needs. See header of script for further" echo " information." DSI_Exit fi # get parameters DSI_EvaluateParameters "$#" "$1" "$2" "$3" "$4" result=$? if [ $result -gt 0 ]; then DSI_PrintUsage DSI_Exit fi # for --extract command only: # get list of files/directories to be extracted for ((i=4; i <= $#; i++)); do temp=\$\{$i\} paraNumsOfFiles="$paraNumsOfFiles \"$temp\"" done # execute command case "$action" in "--full") echo "making full archive: "$ARCH_PATH"/"$archive echo "" echo "Press any key to start or ctrl-c to cancel." read -s -n 1 startTime=$(date +%s) $DAR_PROG --create "$ARCH_PATH/$archive" -R $DIR_ROOT $OPT_FULL $FILE_NOCOMPRESS $DIRLIST_EXCL $DIRLIST_INC endTime=$(date +%s) DSI_PrintDuration $startTime $endTime ;; "--diff") echo "making differential archive: "$ARCH_PATH"/"$archive echo "based on previous archive: "$ARCH_PATH"/"$archive_prev echo "" echo "Press any key to start or ctrl-c to cancel." read -s -n 1 startTime=$(date +%s) $DAR_PROG --create "$ARCH_PATH/$archive" -A "$ARCH_PATH/$archive_prev" -R "$DIR_ROOT" $OPT_DIFF $FILE_NOCOMPRESS $DIRLIST_EXCL $DIRLIST_INC endTime=$(date +%s) DSI_PrintDuration $startTime $endTime ;; "--list") $DAR_PROG --list $OPT_LIST "$ARCH_PATH/$archive" ;; "--extract") echo "restoring from archive: $ARCH_PATH/$archive" echo "destination: $dest_dir" echo "" echo "Press any key to start or ctrl-c to cancel." read -s -n 1 eval $DAR_PROG --extract \"$ARCH_PATH/$archive\" -R \"$dest_dir\" $OPT_EXTRACT "$paraNumsOfFiles" ;; "--help") DSI_PrintUsage echo "" DSI_PrintHelp ;; *) echo "internal ERROR: unknown command" DSI_Exit ;; esac DSI_Exit #*** EOF ***