#!/bin/sh #---------------------------------------------------------------------------------------- # /var/install/bin/backup-file - create backup file # # Creation: 2003-12-25 jed # Last Update: $Id$ # # Copyright (c) 2003-2010 the eisfair team, team(at)eisfair(dot)org # # Parameters: # # backup # or # backup [ -q, --quiet ] file-to-backup [backup-suffix] # [-quiet] old form (deprecated) # # 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. #---------------------------------------------------------------------------------------- # include eislib . /var/install/include/eislib # include function library . /var/install/bin/config_shlib #debug='true' #trace='true' pgmname=`basename $0` # # move_old_backup_files # ===================== # # Parameters: $1 source file # $2 'quiet' - disable screen output # # Returns: 0 move Ok. # 1 failure # move_old_backup_files () { [ "$debug" = 'true' ] && echo "call move_old_backup_files: $*" [ "$trace" = 'true' ] && set -x source_file=$1 quiet=$2 # check if old backup files exist ls "$source_file".* >/dev/null 2>&1 if [ $? -eq 0 ] then if [ "$quiet" != "quiet" ] then # move old backup files to new location mecho "move old backup file(s) to new directory ..." fi for inline in $source_file.* do # Thu Dec 25 14:45:39 2003 -> 2003.12.25.14.45.39 # new syntax with coreutils 8.4 # -rw------- 1 root root 15775 2010-09-09 18:07:25.000000000 +0200 base # so it musst change the separator # I change to awk (hbfl) datestr=`ls --full-time $inline | awk '{ print $6, $7 }'` datestr=`date -d "$datestr" +%Y-%m-%d-%H-%M-%S` # keep original filename and append suffix if [ "$quiet" != "quiet" ] then mv -v "$inline" "$backupd/`basename $inline`.$datestr" else # quiet mv "$inline" "$backupd/`basename $inline`.$datestr" fi done fi } #---------------------------------------------------------------------------------------- # main #---------------------------------------------------------------------------------------- if [ $# -gt 0 ] then case "$1" in "-q"|"--quiet"|"-quiet") quiet_flag='quiet' shift ;; esac # get file to backup source_file="$1" source_path="`dirname $source_file`" source_name="`basename $source_file`" if [ $# -gt 1 ] then file_suffix=$2 else file_suffix='' fi if [ "$source_path" = "." -o "$source_path" = "$configd" ] then # default directory operation move_old_backup_files $configd/$source_name $quiet_flag backup_config $source_name $configd/$source_name "$file_suffix" $quiet_flag else # individual directory operation backupd=$source_path backup_config $source_name "$source_file" "$file_suffix" $quiet_flag fi else # no file name given - show help mecho " Usage: $pgmname [-quiet] file-to-backup [backup-suffix]" mecho fi