From: Zoran Dzelajlija Date: Sat, 30 Apr 2005 02:25:53 +0000 (+0000) Subject: r61: cp_check_and_backup(), kao cp_backup_conffile ali vraca false (3) X-Git-Tag: debian/3.0.0~45 X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=commitdiff_plain;h=f04eccdf6856210fdac3eaabf4f98134945e3060;p=carnet-tools-cn.git r61: cp_check_and_backup(), kao cp_backup_conffile ali vraca false (3) ako nije napravljeno nista. --- diff --git a/carnet-tools.7 b/carnet-tools.7 index 35f5702..958eb04 100644 --- a/carnet-tools.7 +++ b/carnet-tools.7 @@ -72,9 +72,18 @@ da nije naveden \fIinterface\fR argument, vraca CIDR sucelja preko kojeg ide default route, a ako isti nije definiran, vraca CIDR loopback sucelja (lo). .TP -\fBcp_backup_conffile\fR \fIfile\fR -Funkcija backupira datoteku u /var/backups/ direktorij. Po -potrebi rotira, ako postoje neke razlike. +\fBcp_backup_conffile\fR \fIfile\fR [\fIbackup_file\fR] +\fBcp_check_and_backup\fR \fIfile\fR [\fIbackup_file\fR] +Funkcije backupiraju datoteku, pretpostavljeno u /var/backups/ direktorij +sa .bak nastavkom. Po potrebi rotira, ako postoje neke razlike. Opcionalni +argument \fIbackup_file\fR zamjenuje ime backup datoteke u /var/backups +nekim drugim. Na primjer: +cp_backup_conffile config.php + - backup ide u /var/backups/config.php.bak +cp_backup_conffile apache.conf squirrelmail-apache.conf + - backup ide u /var/backups/squirrelmail-apache.conf.bak +cp_backup_conffile uspjesno zavrsi ako nije bilo potrebno izvrsiti backup, +dok cp_check_and_backup u tom slucaju vraca status 3. .TP \fBcp_check_and_sed\fR \fIregexp\fR \fIsed\fR \fIfile\fR [\fIfile\fR ...] Funkcija trazi (egrep) regularni izraz \fIregexp\fR u datotekama, te ako diff --git a/functions.sh b/functions.sh index 773e522..2094e0a 100644 --- a/functions.sh +++ b/functions.sh @@ -139,9 +139,17 @@ cp_get_netaddr() { # by ico, Tue, 15 Mar 2005 14:04:21 +0100 cp_backup_conffile() { - [ "$CP_SCRIPT_DEBUG" ] && set -vx - local file_bak + cp_check_and_backup "$@" +} +cp_check_and_backup() { + [ "$CP_SCRIPT_DEBUG" ] && set -vx + local file_bak check did + + if [ "x$1" = "x-r" ]; then + check=1 + shift + fi if [ -z "$1" ]; then return 1 fi @@ -149,17 +157,28 @@ cp_backup_conffile() { echo "cp_backup_conffile: $1: No such file" 1>&2 return 1 fi + if [ -z "$2" ]; then + file_bak="/var/backups/`basename $1`.bak" + else + file_bak="/var/backups/`basename $2`.bak" + fi - file_bak="/var/backups/`basename $1`.bak" - - if [ ! -f $file_bak ]; then - cp -pf "$1" $file_bak + if [ ! -f "$file_bak" ]; then + cp -pf "$1" "$file_bak" + did=1 else - if ! cmp -s "$1" $file_bak; then - /usr/bin/savelog -p -c 7 $file_bak > /dev/null 2> /dev/null - cp -pf $1 $file_bak + if ! cmp -s "$1" "$file_bak"; then + /usr/bin/savelog -p -c 7 "$file_bak" > /dev/null 2> /dev/null + cp -pf "$1" "$file_bak" + did=1 fi fi + + if [ "$check" -a "$did" ]; then + return 0 + else + return 3 + fi } # by jelly, Tue, 15 Mar 2005 14:04:21 +0100