kojeg ide default route, a ako isti nije definiran, vraca CIDR\r
loopback sucelja (lo).\r
.TP\r
-\fBcp_backup_conffile\fR \fIfile\fR\r
-Funkcija backupira datoteku u /var/backups/ direktorij. Po\r
-potrebi rotira, ako postoje neke razlike.\r
+\fBcp_backup_conffile\fR \fIfile\fR [\fIbackup_file\fR]\r
+\fBcp_check_and_backup\fR \fIfile\fR [\fIbackup_file\fR]\r
+Funkcije backupiraju datoteku, pretpostavljeno u /var/backups/ direktorij\r
+sa .bak nastavkom. Po potrebi rotira, ako postoje neke razlike. Opcionalni\r
+argument \fIbackup_file\fR zamjenuje ime backup datoteke u /var/backups \r
+nekim drugim. Na primjer:\r
+cp_backup_conffile config.php\r
+ - backup ide u /var/backups/config.php.bak\r
+cp_backup_conffile apache.conf squirrelmail-apache.conf\r
+ - backup ide u /var/backups/squirrelmail-apache.conf.bak\r
+cp_backup_conffile uspjesno zavrsi ako nije bilo potrebno izvrsiti backup,\r
+dok cp_check_and_backup u tom slucaju vraca status 3.\r
.TP\r
\fBcp_check_and_sed\fR \fIregexp\fR \fIsed\fR \fIfile\fR [\fIfile\fR ...]\r
Funkcija trazi (egrep) regularni izraz \fIregexp\fR u datotekama, te ako\r
# 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
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